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:
#!/bin/sh

echo #
echo # Mount NetworkDrive
echo #
# NAS IP address
host=192.168.1.2

# Local Network Range
LOCAL_NETWORK=192.168.1.

# NAS MAC Address
MAC_ADDRESS=00:00:00:00:00:00

# Share to mount
MNT_POINT=/Volumes/Data
VOLUME=/Volumes/
# Share 1 Name
SHR1=Data

# 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..."
  else
    echo "Ping unsuccessful - Device sleeping"
    echo "Send WAKE UP signal to the device"
    wol -q $MAC_ADDRESS
    echo "Waiting for device..."
    sleep 240
  fi

  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
    dir1=${VOLUME}${SHR1}
    if [ ! -d "$dir1" ]; then
      # Can't Find Directory So Create It
      echo "Creating Mount Point: $dir1";
      mkdir "$dir1"
    else
      echo "Found Mount Point: $dir1"
    fi
    if [ -d "$dir1" ]; then
      echo "Mounting... afp://$host/$SHR1 $VOLUME$SHR1"
      mount_afp afp://"$host""/$SHR1/" "$VOLUME""$SHR1/"  
    fi
  else
  echo "NAS already mounted!"
  fi
else
  echo "No Valid Network Connection Available... this script is useless..."
fi
# NOTE: If you have other Shell Scripts, or the Teriminal.app is running
#       enabling the next line will cause the entire Terminal.app 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)
 
[13,570 views]  

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" http://www.doogul.com/software/wom/



[ 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: http://www.readpixel.com/wakeonlan/index.html
(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 http://hints.macworld.com/article.php?story=20071023211137834 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 | # ]