NASLite Network Attached Storage

www.serverelements.com
Task-specific simplicity with low hardware requirements.
It is currently Fri Dec 14, 2018 11:55 pm

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Apr 26, 2006 7:52 pm 
Offline

Joined: Thu Aug 11, 2005 6:31 am
Posts: 52
Location: Brighton, UK
Hi guys,
As it proved too complicated to teach my wife to telnet, I ended up writing this script to eject my disks and shutdown my NASLite server, I thought maybe other macusers might be interested.

For beginners like me, here's what you do:

- create a new, blank script in Script Editor (that's in Applications/Applescript)
- copy the code into it and save as an application or a script (named for instance "Close Server", as it is very pragmatically called in our computer)

If you save as a script, place it in the ~/library/scripts folder (you might have to create this folder if it isn't there). You then open Applescript Utility and tick "Show Script Menu in menu bar" to, erm, access the script from the script menu in your menu bar. Your call really.

Now please beware this is my first script. I do not pretend to know the first thing about error handling etc. It works on my setup, but extreme caution should be the norm as it is, I repeat, my very first script (took me three hours to complete). You use this at your own risk. So any improvements (such as afore mentioned error handling) are very much welcome.

A few comments:

- I have 3 disks in my NASLite. I have therefore used the "repeat with i from 1 to 3", but you should change that last value to the number of disks you have

- You will need to replace "nas" by the password you use to telnet in your server (but still in double quotes), and change the local IP

- I have included a "delay 5" (5 seconds delay) as it sometimes takes a few seconds for the server to reply to the telnet command. If you get error messages or the terminal mashes up the admin and password entries, try a bigger value here (or clean your system with Doktor Kleanor, worked wonders on mine)

Code:
if button returned of (display dialog "Eject disks & shutdown NASLite server?" buttons {"Yes", "No"} default button 2 with icon caution with title "Close Server") is "yes" then
   
   set MyUsrName to "admin" as string
   set MyPass to "nas" as string
   
   tell application "Finder"
      repeat with i from 1 to 3
         set MyDisk to "Disk-" & i as string
         if disk MyDisk exists then
            eject disk MyDisk
         end if
      end repeat
   end tell
   
   tell application "Terminal"
      activate
      tell application "Finder" to set visible of process "Terminal" to false
      do script "telnet 192.168.0.20" in front window
      delay 5
      do script MyUsrName in front window
      do script MyPass in front window
      do script "8" in front window
      do script "y" in front window
      delay 2
      quit
   end tell
end if


[edit] I have just bought an AppleScript book :mrgreen:
I'll probably post improvements myself as I learn, I'm thinking first of a dialog to confirm actions, and maybe later script an entire interface to replace the terminal.


Last edited by etien on Thu May 04, 2006 2:16 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 1:49 pm 
Offline

Joined: Thu Aug 11, 2005 6:31 am
Posts: 52
Location: Brighton, UK
added a delay command before quitting the Terminal as it didn't leave enough timefor NASLite to actually receive the shutdown command.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 04, 2006 2:11 pm 
Offline

Joined: Thu Aug 11, 2005 6:31 am
Posts: 52
Location: Brighton, UK
Here's another script to connect to your disks:

Code:
-- This script attempts to connect your mac to the NASLite disks.
-- Change the "3" in second line to your total number of disks.
-- Change the IP address to your NAS box IP address.
-- The scrip also closes all windows opened at connect (although this sometimes fail for some reason I won't bother to explore)

tell application "Finder"
   repeat with i from 1 to 3
      set The_Disk to "Disk-" & i as string
      if not (disk The_Disk exists) then
         try
            open location "nfs://192.168.0.20/export/" & The_Disk
            delay 1
            if window The_Disk exists then
               close window The_Disk
            end if
         end try
      end if
   end repeat
end tell


Obviously you need to change the IP and the total number of disks (in the line "repeat with i from 1 to number of disks").

You can also replace "nfs" by "smb" if you prefer.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group