myNAS shutdown

Arrêt automatique à une heure donnée(Éditer)

~# sudo -s
~# 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 ;)
"wake on line" permet de redémarrer sans se déplacer


Advanced shutdown script for power-saving(Éditer)

c.f. advanced-shutdown-script

~# 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:

  1. 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