Simple Shell Script To Wake Up NAS Devices Using Linux or Unix Computer

by on May 13, 2012 · 0 comments

A simple bash shell script to wake up nas devices / home servers using mac address.

  1. #!/bin/bash
  2. # A simple shell to Wake Up nas devices / home servers
  3. # Tested on RHEL, Debian and Ubuntu base desktop systems.
  4. # ----------------------------------------------------------------------------
  5. # Written by Vivek Gite <http://www.cyberciti.biz/>
  6. # (c) 2012 nixCraft under GNU GPL v2.0+
  7. # ----------------------------------------------------------------------------
  8. # Last updated: 14/May/2012
  9. # ----------------------------------------------------------------------------
  10.  
  11. # add your nas devices mac address here #
  12. _nas03="00:xx:yy:zz:aa:aa"
  13. _nas02="xx:yy:zz:aa:bb"
  14. _nas01="00:xx:yy:zz:aa:cc"
  15.  
  16.  
  17. # path to wakeonlan #
  18. __wakeupserver="/usr/bin/wakeonlan"
  19.  
  20. # who am I ? #
  21. _me="${0##*/}"
  22.  
  23. # send magic packet #
  24. __wakeup(){
  25. local n="$1"
  26. [[ "$n" == "" ]] && { echo "$_me ($FUNCNAME#$LINENO) error: Mac address not set."; exit 1; } || $__wakeupserver $n
  27. }
  28.  
  29. ## main logic ##
  30. case $_me in
  31. wakeup.nas03) __wakeup $_nas03;;
  32. wakeup.nas02) __wakeup $_nas02;;
  33. wakeup.nas01) __wakeup $_nas01;;
  34. *) echo "$_me I can not understnad the request."
  35. esac
  36.  

How do I use this script?

First, install Wake-on-LAN (WOL) client under Unix or Linux operating systems.

Next, download this script and put in your home directory as master.wol.sh
wget -O 558.sh.zip 'http://bash.cyberciti.biz/dl/558.sh.zip?id=82aa046ab4872920e2fb0c9add0bd169'
unzip 558.sh.zip
mv 558.sh ~/bin/master.wol.sh
chmod +x ~/bin/master.wol.sh

Edit the script and set nas server mac address. Finally, create a symbolic link using ln command:
ln -s master.wol.sh wakeup.nas01
ln -s master.wol.sh wakeup.nas02
ln -s master.wol.sh wakeup.nas03

To wake up nas01 using WOL, enter:
/path/to/wakeup.nas01



4000+ howtos and counting! If you enjoyed this article, join 45000+ others and get free email updates!

Click here to subscribe via email.

Previous Script:

Next Script: