I created an .sh file for my remote laptop that would play an alarm file through ffplay and send me a telegram message whenever the power plug got disconnected. The file worked great when I ran it in a terminal so I though I'll just create a service for it.
Followed a tutorial to make it work but found out that the audio file was no longer playing when using it as a service so I decided to delete the service for which I followed this tutorial.
When I check the service by using $ systemctl status battery_alarm.service the file can no longer be found so I figured it was all done but even after restarting the laptop, update & upgrade, it is still running somewhere.
It's not a big deal since I still get my Telegram message but I would like to solve this mystery and find out where and what I need to delete to have this stop. Any advice for this noob? :-)
edit: The .sh file used for the service was:
#! /bin/bash
echo "monitoring"
power=$(cat /sys/class/power_supply/BAT0/status)
# Set the API token and chat ID
API_TOKEN="<removed for obvious reasons :-)>"
CHAT_ID="1234567890"
Set the message text
MESSAGE="HP Victus Unplugged"
while true; do
actual=$(cat /sys/class/power_supply/BAT0/status)
echo $actual
if [ $actual != $power ]; then
power=$actual
echo $actual
fi
if [ $actual == "Discharging" ]; then
echo "discharging"
# Use the curl command to send the message
curl -s -X POST https://api.telegram.org/bot$API_TOKEN/sendMessage -d chat_id=$CHAT_ID -d text="$MESSAGE"
amixer -D pulse sset Master 100%
ffplay -autoexit -nodisp critical.mp3
fi
sleep 10
done
Link to the audio file for those who would like to have a copy
edit: After I changed the message in the checkpower.sh file, I now get 2 different messages. The new message in the modified checkpower.sh containing the state and battery percentage and the old message I used to have. So it seems like when I created the service, a copy of the checkpower.sh file was created which still runs somewhere. One message informing me is enough for me. Any idea how to find this unwanted service and kill it?
edit: I tried the forkit way which gave me the pids for the exec lines
15:52:07 exec 112099 cat /sys/class/power_supply/BAT0/status
15:52:07 exec 112100 curl -s -X POST https://api.telegram.org/bot
15:52:07 exec 112102 amixer -D pulse sset Master 100%
15:52:07 exec 112104 ffplay -autoexit -nodisp critical.mp3
15:52:07 exec 112108 sleep 10
The output I got when trying these pids was:
(base) qwerty@qwerty-Victus:~$ systemctl status 112099
Failed to get unit for PID 112099: PID 112099 does not belong to any loaded unit.
(base) qwerty@qwerty-Victus:~$ systemctl status 112100
Failed to get unit for PID 112100: PID 112100 does not belong to any loaded unit.
(base) qwerty@qwerty-Victus:~$ systemctl status 112102
Failed to get unit for PID 112102: PID 112102 does not belong to any loaded unit.
(base) qwerty@qwerty-Victus:~$ systemctl status 112104
Failed to get unit for PID 112104: PID 112104 does not belong to any loaded unit.
(base) qwerty@qwerty-Victus:~$ systemctl status 112108
Failed to get unit for PID 112108: PID 112108 does not belong to any loaded unit.
(base) qwerty@qwerty-Victus:~$ systemctl status --user 112099
Failed to get unit for PID 112099: PID 112099 does not belong to any loaded unit.
(base) qwerty@qwerty-Victus:~$ systemctl status --user 112100
Failed to get unit for PID 112100: PID 112100 does not belong to any loaded unit.
(base) qwerty@qwerty-Victus:~$ systemctl status --user 112102
Failed to get unit for PID 112102: PID 112102 does not belong to any loaded unit.
(base) qwerty@qwerty-Victus:~$ systemctl status --user 112104
Failed to get unit for PID 112104: PID 112104 does not belong to any loaded unit.
(base) qwerty@qwerty-Victus:~$ systemctl status --user 112108
Failed to get unit for PID 112108: PID 112108 does not belong to any loaded unit.