LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   WOL startup script? (https://www.linuxquestions.org/questions/linux-general-1/wol-startup-script-702284/)

BassKozz 02-04-2009 12:01 PM

WOL startup script?
 
My NAS powers off every-night to save electricity thanks to a little script I created (see: Advanced Shutdown Script - Powersaving).
But now every-morning, before I power on my desktop I need to boot up my NAS 1st :(, and I am lazy, so the energy exerted to push the power button on my NAS box can be better used else where :p

So I created a little script that will wake up my NAS box and mount the share(s):
Code:

#!/bin/sh
###
# 2/3/09
# wake-NAS.sh
# Wake-On-Lan wake NAS Script
###

echo "Begin: $(date)" >> /home/user/scripts/wake-NAS.log
wakeonlan AA:BB:CC:DD:EE:FF >> /home/user/scripts/wake-NAS.log
sleep 5m
mount -a >> /home/user/scripts/wake-NAS.log
echo "End  : $(date)" >> /home/user/scripts/wake-NAS.log

I am using Ubuntu,
So I put this script in /etc/init.d/ and ran 'update-rc.d wake-NAS.sh defaults' and rebooted, and it worked :D

However, there are two problems:
  1. It caused my bootup time to be +5minutes, due to the line "sleep 5m", I figured it would just run the script in the background on bootup and not holdup the boot, but that's not the case...
    Is there a way to get this to run in the background so it doesn't hold up my bootup times?
    Or maybe I could make the "mount -a" a separate script that runs after the machine is fully booted (i.e. in Ubuntu I could use System>Preferences>Sessions).
  2. It runs at shutdown as well, which is pointless, I don't want to wake my NAS when I am shutting down, nore do I want to mount my shares (mount -a) :(
Any idea's?
If anyone knows of a better way of going about this, I am all ears

arizonagroovejet 02-04-2009 03:21 PM

For issue 1

Code:

if [ $# -ne "0" ]; then
  put your script here

  exit
fi

exec $0 foo &

You might need to change your #!/bin/sh to #!/bin/bash for the if statement to work, I can't recall or be bothered to test.

For issue 2, look in the directories /etc/init.d/rc[1-5].d (or is in /etc/rc[1-5].d on Ubuntu, I forget) and you'll probably find symbolic links to your wake-NAS.sh script. One link will have a name starting with S and the other with K. Delete the one starting with K as that's the one that will be run on shutdown. It's something like that anyway, I don't have a Ubuntu install to check specifics on.


All times are GMT -5. The time now is 02:25 PM.