Just checking that this is not crazily wrong...
(I am guessing this make the script automatically run every 5 minutes of every hour and every day)Code:00,05,10,15,20,25,30,35,40,45,50,55 * * * * root /home/sim/poweroff.sh
I added that line using nano into /etc/crontab and then made a new file in /home/sim/ called poweroff.sh using nano containing:
(this is the script - blinedly copied)Code:#!/bin/bash threshold=55 username=sim inactive=`who -a | grep $username | cut -c 45-46 | sort | grep [0-9] | head -n1 | sed 's/ //g'` if [ "$inactive" != "" ]; then echo "Idle time is: " $inactive if [ "$inactive" -ge "$threshold" ]; then echo "Threshold met so issuing shutdown command" /sbin/shutdown -h now else echo "Below threshold" fi else echo "Idle time is: 0" fi echo "Ending"
Then I ran
So to test, I have turned the server on and not touched anything. I will check in an hour to see if it has turned itself offCode:sudo chmod +x poweroff.sh


LinkBack URL
About LinkBacks
Reply With Quote




