Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Waking up a NAS device (a complete solution) Network
I purchased a LaCie NAS device, and I make use the Deep Sleep mode available on the device to reduce the power comsumption. The device has a software called LaCie Network Assistant and there is a function to Wake Up the device. According to the manual this function should remember the MAC address after the first use but it does not. That's why I started looking for another way of waking up the device automatically.

I found this hint on your site but it doesn't really do what I wanted.

Then I found WakeOnLan for use from the command line. There's a link to the developer page.

Download the file and place the wol executable inside /usr/bin.

The easiest way to do this is by using the Finder menu Go » Go To Folder » /usr/bin/. Just drag-n-drop the file there. You may need to chmod the permissions of the file to 755.

I was then able to create this script. Here is what it does:
  • Look for a network connection (I have a laptop, so I don't need the NAS all the time).
  • Check if the NAS device is available.
  • If not, wake up the NAS device (wait for the NAS to wake up... mine takes about three minutes to come up, using a RAID5).
  • Mount the drive point.
  • Exit Terminal.
Here's the script. Open your favorited text editor and copy/paste this:

echo #
echo # Mount NetworkDrive
echo #
# NAS IP address

# Local Network Range

# NAS MAC Address

# Share to mount
# Share 1 Name

# Look for network connection
echo "Looking for the right network connection..."
outp=`ifconfig | grep "inet ${LOCAL_NETWORK}*"`

# echo "$outp"

if [ "$outp" != "" ]; then
  echo "We have a connection!"

  # Ping the host to see if it exists
  echo "Ping $host..."
  outp=`ping -c 1 $host | grep "0.0% packet loss"`
  # echo "$outp"
  if [ "$outp" = "1 packets transmitted, 1 packets received, 0.0% packet loss" ]; then
    echo "Found $host..."
    echo "Ping unsuccessful - Device sleeping"
    echo "Send WAKE UP signal to the device"
    wol -q $MAC_ADDRESS
    echo "Waiting for device..."
    sleep 240

  MNT_INFO=$(mount | awk -v mnt="$MNT_POINT" '{if ($3 == mnt) print $0}')
  if ["$MNT_INFO" == ""]; then
    echo "Mount point not available, perhaps just woke up"
    echo "Check if Directory exist..."
    # Share 1
    if [ ! -d "$dir1" ]; then
      # Can't Find Directory So Create It
      echo "Creating Mount Point: $dir1";
      mkdir "$dir1"
      echo "Found Mount Point: $dir1"
    if [ -d "$dir1" ]; then
      echo "Mounting... afp://$host/$SHR1 $VOLUME$SHR1"
      mount_afp afp://"$host""/$SHR1/" "$VOLUME""$SHR1/"  
  echo "NAS already mounted!"
  echo "No Valid Network Connection Available... this script is useless..."
# NOTE: If you have other Shell Scripts, or the is running
#       enabling the next line will cause the entire to close.
#  If you are sure that you can kill the Terminal process feel free to 
#  uncomment the following line so that the Terminal window the script brings
#  up will automatically close when finished 
KillAll Terminal
Save the file as 'MountNAS.command' and put it somewhere in your command path. Set the permissions to 755.

[crarko adds: I haven't tested this one. I mirrored the script here.]
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)

Waking up a NAS device (a complete solution) | 6 comments | Create New Account
Click here to return to the 'Waking up a NAS device (a complete solution)' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Waking up a NAS device (a complete solution)
Authored by: auntchilada on Dec 13, '10 10:12:53AM
KillAll Terminal

guh! poor form.

[ Reply to This | # ]

Waking up a NAS device (a complete solution)
Authored by: TvE on Dec 13, '10 11:08:34AM

exit 0

;-) TvE

[ Reply to This | # ]
Waking up a NAS device (a complete solution)
Authored by: Asmus Vierck on Dec 13, '10 10:38:03AM

Minor issues: I think you should consider using an Automator App (using the "run shell script" action) instead of creating a .command and then killing the Terminal. And maybe using log and/or growl notifications instead of all the echos would make that nicer, too.. But still: nice idea so far!

[ Reply to This | # ]
Waking up a NAS device (a complete solution)
Authored by: stevec on Dec 13, '10 12:04:41PM

Or you could try this little app "WakeOnMac"

[ Reply to This | # ]
Waking up a NAS device (a complete solution)
Authored by: auco on Dec 13, '10 10:41:31PM

I use wakeonlan for Mac, it comes with a dashboard widget:
(freeware, not affiliated with the developer btw)

There are also some networking iPhone apps that support sending the wake packet as well...

[ Reply to This | # ]
Waking up a NAS device (a complete solution)
Authored by: TonyT on Dec 15, '10 07:17:30PM

Not sure why doesn't really do what you wanted. It sends the magic packet and you can call the python script in your bash script or include it in the script with a "Here Doc" block

Using an app to send a magic packet is overkill.

Edited on Dec 15, '10 07:20:55PM by TonyT

[ Reply to This | # ]