You are not logged in.
Hi, at work we have development server which gets shutdown automatically at night via cron to save power.
Our firewall starts the server just before office hours via WOL.
So far so good.
Well, as part of the shutdown process, I call a complicated backup script, which creates LVM snapshots and creates backups to various other servers.
The shutdown script gets called via cron at 19:00 and is really simple:
echo "Running Backups before shutdown"
/root/Scripts/LVMbackup.sh
echo "Activating WOL before shutdown"
/usr/sbin/ethtool -s eth0 wol g
sleep 10
/sbin/shutdown -h -P now
Sometimes it happens that the LVMbackup script hangs and runs until the morning. Or lets just say, maybe the backup procedure takes too long since many files were changed and the upload wasn't finished yet.
Well whatever the reason, it's possible that the LVMbackup script finishes after 08:55a.m and then shuts down the server. The firewall issues a WOL to that server 08:55am.
It happens rarely, but in effect this means, people are working on the server, and suddenly it shuts down unexpectedly.
I was thinking of implementing a check function into the shutdown script so that if its already 08:55am in the morning, it simply exits and doesn't proceed with the shutdown command.
Can anyone help me out with this? I'm still a bit inexperienced with more advanced bash scripting.
Last edited by ChojinDSL (2012-07-05 09:15:33)
Offline
You can do it like this
echo "Running Backups before shutdown"
/root/Scripts/LVMbackup.sh
echo "Activating WOL before shutdown"
/usr/sbin/ethtool -s eth0 wol g
sleep 10
# Current hour of the day (0-23)
HOUR=$(date +%H)
if [ $HOUR -lt 9 ] || [ $HOUR -ge 19 ] ; then
# Only shut down if HOUR is less than 9 or greater than 19
/sbin/shutdown -h -P now
fi
Last edited by Isola (2012-07-05 09:12:47)
Offline
Cool, thanks!
Offline