I'm really new to ubuntu server, and i've been having a lot of issues with crontab across this week and i can't really figure out what's wrong with it, i tried everything i saw here to no avail.
So, i have a script that in theory should shut off the server after a few minutes of net inactivity. The script executes without any problem, and works perfectly if done so manually.
The issue i've been facing happens when I try to setup cron to execute this script.
Here's the code
#!/bin/bash
set -o nounset -o errexit -o pipefail
MARKER_FILE="/tmp/ssh-inactivity-flag"
STATUS=$(netstat | grep ssh | grep ESTABLISHED &>/dev/null && echo active || echo inactive)
if [ "$STATUS" == "inactive" ]; then
if [ -f "$MARKER_FILE" ]; then
echo "Powering off due to ssh inactivity."
rm --force "$MARKER_FILE"
/sbin/poweroff # See https://unix.stackexchange.com/a/196014/56711
else
# Create a marker file so that it will shut down if still inactive on the next time this script runs.
echo "El cabron aun no se ha ido :("
touch "$MARKER_FILE"
fi
else
# Delete marker file if it exists
rm --force "$MARKER_FILE"
echo "No se va el pussi"
fi
Here's the crontab setting:
*/1 * * * * root /home/angel/idle.sh
And here's what it returns on /var/log/syslog
Jun 29 13:37:01 torreon CRON[1951]: (angel) CMD (root /home/angel/idle.sh)
In theory cron is executing the script, but it doesn't seem to work or return anything. I'm really lost and i don't know what i could have done wrong, so if anyone can please guide me it would be greatly appreciated.
(Also i've tried with other scripts that are just like one line of code and those didn't work neither.)