myNAS shutdown

Différence entre les versions 2011/05/04 20:10 et 2011/05/04 20:03.
!! Arrêt automatique à une heure donnée

~# sudo -s {br} ~# crontab -e
{{
# m h  dom mon dow   command
0 0 * * * /sbin/shutdown -P +60
}}

Ici, arrêt programmé à 01:00 A.M. quand tout le monde dort ;) {br} "wake on line" permet de redémarrer sans se déplacer

----

!! Advanced shutdown script for power-saving

c.f. [advanced-shutdown-script|http://www.linuxquestions.org/questions/linux-general-1/need-help-creating-an-advanced-shutdown-script-for-power-saving-701727/]

~# net status shares parseable
~# net status shares parseable

Advanced Shutdown Script (check for running services)

I’ve updated my “Advanced Shutdown Script” to now check for running services/processes before shutting down, this way the script will check and see if I a set of services are running or not, and if so exit.  The reason why I wanted to have this feature is because my NAS box runs backups and I wouldn’t want it to shutdown while running a backup.

So here it is:
{{
#!/bin/sh
###
# 2/4/09
# adv-shutdown.sh
# Advanced Shutdown Script
# Ref – http://basskozz.wordpress.com/2009/02/04/advanced-shutdown-script-part-2-check-for-services/
###
SERVICE_LIST=’mysecurebackup’
IP_LIST=’192.168.1.101 192.168.1.102 192.168.1.103 192.168.1.104‘

for SERVICE  in $SERVICE_LIST; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo “$SERVICE service is running: $(date)” >> /home/user/scripts/adv-shutdown.log
exit
else
echo “$SERVICE is NOT running: $(date)” >> /home/user/scripts/adv-shutdown.log
fi
done

ALIVE=0
for IP  in $IP_LIST; do
ping -q -c1 -w5 $IP
if [ $? -eq 0 ]; then
ALIVE=1
echo “$IP is alive: $(date)” >> /home/user/scripts/adv-shutdown.log
break
fi
done

if [ $ALIVE -eq 0 ]; then
echo “***ShutDown***  $(date)” >> /home/user/scripts/adv-shutdown.log
echo “###########################” >> /home/user/scripts/adv-shutdown.log
/sbin/shutdown -h now
fi}}

You can put any number of services in the “SERVICE_LIST” variable separated by a space and it will check if any of them are running. i.e.:
SERVICE_LIST=’program1 program2 program3′
My backup program is called “mysecurebackup” so I only have that one in there right now.
Now I don’t need two separate lines in my ‘sudo crontab’ because the script will check and see if a backup is running, so my sudo crontab looks like this now:
# Run Advanced Shutdown script every 10minutes between 1-5:50am everyday
0,10,20,30,40,50 01-05 * * * /home/user/scripts/adv-shutdown.sh