Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 1, 2007, 01:29 AM   #1
LethalWolfe
macrumors Demi-God
 
LethalWolfe's Avatar
 
Join Date: Jan 2002
Location: Los Angeles
Script to poll FW drives every 10min?

I have 3 FW drives that go to sleep (no matter what) and I was wondering how to make an Apple Script that could poll the drives every X minutes to keep them awake. I've never worke w/Apple Script before so guidance would be great, and someone actually writing the script for me would be awesome.


Lethal
__________________
Looking For Lenny - documentary about comedian Lenny Bruce's timeless impact on stand-up comedy & Free Speech.
Netflix, iTunes, Amazon, Hulu
LethalWolfe is offline   0 Reply With Quote
Old Jul 1, 2007, 02:08 AM   #2
Super Macho Man
macrumors 6502a
 
Join Date: Jul 2006
Location: Hollywood, CA
Were you aware of pmset? I think "pmset -a disksleep 0" should do it, maybe.

To actually poll the drives, how about a shell script instead - name it "nosleep.sh", probably has to be run as root. Could also name it .command instead of .sh in order to make it double-clickable but I'm not sure how it would run as root in that case. (I haven't tested it):

Code:
#!/bin/sh
# Writes 3 empty files to 3 different drives and
# immediately deletes them every 10 minutes

for (( i = 1; i > 0; i++ ));
do
  touch tempfile /Volumes/name_of_drive1
  touch tempfile /Volumes/name_of_drive2
  touch tempfile /Volumes/name_of_drive3
  rm -f /Volumes/name_of_drive1/tempfile
  rm -f /Volumes/name_of_drive2/tempfile
  rm -f /Volumes/name_of_drive3/tempfile
  sleep 600
done
Super Macho Man is offline   0 Reply With Quote
Old Jul 1, 2007, 04:03 AM   #3
OutThere
macrumors 603
 
OutThere's Avatar
 
Join Date: Dec 2002
Location: NYC
My suggestion would be to use a shell script instead of applescript, and to let cron do the automating, I don't know how much you know about this stuff so I'll keep it simple...

1) Copy this into a plain text file in TextEdit, change the "drive1/2/3" into the names of your drives, and save it as "poll.sh" wherever you want.

Code:
#!/bin/bash

a="/Volumes/drive1/"
b="/Volumes/drive2/"
c="/Volumes/drive3/"

ls $a
ls $b
ls $c
That's basically a script that reads out the names of the files in the root of your drives automatically.

2) Go into the terminal, type:

Code:
sudo cp /the/path/to/poll.sh/ /usr/bin/poll.sh
then
Code:
sudo chmod 777 /usr/bin/poll.sh
that will copy the shell script to a special folder, and set its permissions to be able to be run

3) Again in the terminal, type:

Code:
sudo pico /etc/crontab
then it'll bring up like a really basic text editor, with a list of jobs that your computer will do automatically, so you don't have to run the script by hand. The columns are tab delimited, so keep that in mind. Make the file look like this (or at least add this line if there are others):

Code:
# The periodic and atrun jobs have moved to launchd jobs
# See /System/Library/LaunchDaemons
#
# minute        hour    mday    month   wday    who     command                        
*/8                                           root    sh /usr/bin/poll.sh
That will tell your computer that every 8 minutes it should run the script and get a list of the files on your drives.

Do all that and your problem should be solved.
__________________
puisqu'on est jeune et con, puisqu'ils sont vieux et fous. . .
OutThere is offline   0 Reply With Quote
Old Jul 1, 2007, 05:12 PM   #4
LethalWolfe
Thread Starter
macrumors Demi-God
 
LethalWolfe's Avatar
 
Join Date: Jan 2002
Location: Los Angeles
Cool, thanks guys. I'll try these out in the next day or so.


-Lethal
__________________
Looking For Lenny - documentary about comedian Lenny Bruce's timeless impact on stand-up comedy & Free Speech.
Netflix, iTunes, Amazon, Hulu
LethalWolfe is offline   0 Reply With Quote
Old Jul 3, 2007, 03:35 PM   #5
Poeben
macrumors 6502
 
Join Date: Jul 2004
I've been messing with this for a few days. Here's what I can add to the discussion....

Tiger no longer uses 'cron' to schedule things. You should be using 'launchd' combined with .plist files. I also chose to use 'touch' instead of 'ls' as it should use less resources, at least if there are many files on the drive. I also made my touched file invisible to the finder by prefixing the filename with a dot.

So my script is based on the following command:

touch -m /path/to/.file.txt

and the .plist (saved in ~/Library/LaunchAgents/) is something along the lines of:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.something.nieSchlaf</string>
	<key>Program</key>
	<string>/usr/local/nieSchlaf.sh</string>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/local/nieSchlaf.sh</string>
	</array>
	<key>ServiceDescription</key>
	<string>Will attempt to keep external drives from spinning down by utilizing the 'touch' command</string>
	<key>StartInterval</key>
	<integer>600</integer>
</dict>
</plist>
You will have to make the script executible

chmod +x script.sh

You will also likely have to create the ~/Library/LaunchAgents/ directory.

You set everything in motion using:

launchctl load ~/Library/LaunchAgents/<your_plist_file.plist>

I found this site helpful.
__________________
ćActual post may vary from original thought.
Poeben is offline   0 Reply With Quote
Old Jul 3, 2007, 04:08 PM   #6
SC68Cal
macrumors 68000
 
Join Date: Feb 2006
Quote:
Originally Posted by OutThere View Post
Code:
sudo chmod 777 /usr/bin/poll.sh
that will copy the shell script to a special folder, and set its permissions to be able to be run
Bad Idea. Very Very BAD IDEA. That is way too insecure. Anyone will be able to modify that script into something malicious. You'd get your box owned in no time flat.

I suggest 700 and not running it as root
SC68Cal is offline   0 Reply With Quote
Old Jul 3, 2007, 08:21 PM   #7
zimv20
macrumors 601
 
zimv20's Avatar
 
Join Date: Jul 2002
Location: chicago
Quote:
Originally Posted by Poeben View Post
the .plist (saved in ~/Library/LaunchAgents/)
for clarification: scripts launched from that location will run iff the relevant user is logged in. for the task at hand, that's probably fine.

for those who wish to run a script without regard to who is logged in or not, the .plist file should be placed in:
/Library/LaunchDaemons/

obviously, one has to be logged into root both to do the copy and run the launchctl load command.

also: run launchctl list to verify your load command worked. run launchctl unload <name of .plist> to unload it.
__________________
Oct 2011: check out my band's first album @ boxsetauthentic.com
zimv20 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
JBL OnBeat Micro sleeping after 10min Tulani iPhone Accessories 0 Apr 24, 2014 04:19 AM
Apple script batch shell script prramesh Mac Programming 5 Sep 15, 2013 04:35 AM
naming external drives, hard drives, thum drives for best compatability Sossity Mac Peripherals 1 Apr 5, 2013 04:11 AM
Poll: iPad Mini Pricing Poll gladoscc iPad 22 Oct 14, 2012 08:03 PM
first script/autamator script feed back zyr123 Mac Programming 1 Jul 17, 2012 11:00 AM

Forum Jump

All times are GMT -5. The time now is 07:05 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC