Need terminal syntax for scheduling a unix program
March 23, 2011 7:42 PM   Subscribe

Need help scheduling a unix task under Mac OS. Probably an easy question for those who understand such things.

Hardware: iBook G4 (mid-2005 edition).
Operating System: Mac OS 10.4.11
Program to be run: rss2email
Sheduling program: Lingon 1.2.1

I'm pretty much a newbie to the terminal, but, after updating the default Python install, was able to get rss2email up and running just fine.

To manually execute the program, I use the terminal to navigate into the rss2email-2.71 directory and type:

./r2e run

Per the instructions, here.

Now, what I would like to do is use Lingon (which, as I understand it, provides a GUI for the Mac's native scheduler, launchd) to run rss2email every two hours.

But I can't seem to get the syntax right in Lingon. I tried

/Applications/rss2email-2.71/r2e run

but that doesn't work. I'm guessing it has something to do with the "./" I have to type before the "r2e run" when I manually execute. But I have no idea how to incorporate this syntax into Lingon. Can anyone point me in the right direction?
posted by Alaska Jack to Computers & Internet (16 answers total)
No, you don't need "./" if you're giving the full path. I don't own a copy of Lingon, so I can't be sure how what's going wrong. But it should be producing some sort of .plist file, and if you'd post that I could take a closer look. (The plist would probably be located in /Library/LaunchDaemons.)
posted by vasi at 7:51 PM on March 23, 2011

I found this in Library/LaunchAgents:








Does that help?

- aj
posted by Alaska Jack at 8:02 PM on March 23, 2011

ugh, just munged that. *$!@ nothing can ever be easy.
posted by Alaska Jack at 8:06 PM on March 23, 2011

Here's an approximation, minus the initial "less than" signs on each line, and closing tags.

?xml version="1.0" encoding="UTF-8"?>
!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
plist version="1.0">
posted by Alaska Jack at 8:11 PM on March 23, 2011

I don't know Lingon, but the typical unix way of scheduling jobs is to create an entry in /etc/crontab.

Type "crontab -e" at the command prompt and create an entry something like:

* /2 * * * * /Applications/rss2email-2.71/r2e run

and save the file. That should accomplish what you're trying.

That assumes you can navigate the vi editor though. Not sure if that's a safe assumption or not in this context.
posted by zen_spider at 8:22 PM on March 23, 2011 [1 favorite]

I also don't know Lingon, but another way of scheduling jobs is to create an appointment in iCal. You can set the appointment to run a shell script. iCal does not need to be running for these events to fire. I have found this to be essentially idiotproof, and nicely pointy clicky, if that's a help.

That all said: could this be a permissions issue? Does Lingon run as you, or does it have a user?
posted by pompomtom at 8:38 PM on March 23, 2011

You can invoke an easier editor than vi like so,
EDITOR=/usr/bin/nano; crontab -e
Just follow the instructions at the bottom of the screen to write out your changes and exit. (The ^ means "control key").

Then, assuming cron jobs are fired correctly on your machine, zen_spider's suggestion should work.
posted by Monsieur Caution at 8:40 PM on March 23, 2011

(permissions issue question is because I concur with vasi that the "./" is not a good idea)
posted by pompomtom at 8:40 PM on March 23, 2011

I don't know anything about Lingon, so this is all pure launchd management. on OSX you don't want to use cron.

if you open a terminal window and execute

/Applications/rss2email-2.71/r2e run

does it work correctly? if not, it may be requiring the current directory be /Applications/rss2email-2.71/ in which case add to the plist file you found an entry like


and change the "/Applications/rss2email-2.71/r2e" in ProgramArguments back to the ./r2e that you use in the terminal.

another possibility is that Lingon is creating the plist but isn't loading it (this has changed a couple of times since launchd became the standard in OSX and I don't recall the defaults in 10.4). run

launchctl list | grep rss2email

in a terminal window, and if there's no output then do this

sudo launchctl load /Library/LaunchAgents/com.test.rss2email

to force launchd to notice the new config.
posted by russm at 8:55 PM on March 23, 2011

(I'm assuming that the file you listed above is /Library/LaunchAgents/com.test.rss2email.plist based on the included label. if the file is called something else then use that path in the "launchctl load" command, but you need to strip off the ".plist" from the end.)
posted by russm at 8:57 PM on March 23, 2011

hmmm, are you running an old version of Lingon? I just had a look to see what it does and the only download info seems to be "requires 10.6, get it in the app store"...

but from the manual that's available online it looks like you should be able to go into Expert Mode to add new keys to the plist file - that'd be easier than editing directly to add the WorkingDirectory key...
posted by russm at 9:47 PM on March 23, 2011

Cron still works in OSX, so if you can get it to run under cron, there's no reason not to. But the launchd/Lingon approach should work.

Is the launchd job running as you, or as root? If when you test it in Terminal it runs fine as you, then you should probably set the launchd job to run as you, as well. r2e probably looks for a config or state file in the home directory of the user it's running as.

You could try setting StandardOutPath and StandardErrorPath to somewhere (e.g., some files in /tmp) to see if the job is emitting a useful error message when it dies. (Docs)
posted by hattifattener at 10:46 PM on March 23, 2011

Launch agents (like the one that Lingon has created) are active while a user is logged in on the console, and are run as that user. Launch daemons (not what's been created here) are run as root by default and need UserName/GroupName keys in order to get a non-root environment. There shouldn't be any problem with task ownership as OP has described the setup.

Yeah, an entry in /etc/crontab will work too. I thought cron was shipped disabled by default but it looks like the launchd config for cron is smart enough to start it up if /etc/crontab exists.
posted by russm at 11:12 PM on March 23, 2011

OK, thanks everyone. I'll try going in order.

In the terminal, from my home directory, if I enter the command "/Applications/rss2email-2.71/r2e run" I get:

/Library/Frameworks/Python.framework/Versions/2.7/Resources/ can't open file '': [Errno 2] No such file or directory

Possibly also relevant? When I'm in Applications/rss2email-2.71/ , and I type "./r2e run", it works. But if I just type "r2e run" without the "./", I get this: "-bash: run: command not found"
posted by Alaska Jack at 11:22 PM on March 23, 2011

OK, it looks like r2e is making unwarranted assumptions about the current directory when it is run. Adding the WorkingDirectory key to the plist file should fix it.
posted by russm at 11:38 PM on March 23, 2011

ARRGHGHGHGH! I've been fighting this for the last few hours and am ready to throw in the towel, at least for tonight. Here's what I've got:

[?xml version="1.0" encoding="UTF-8"?]
[!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" ""]
[plist version="1.0"]

Lingon has indeed loaded this. But it just seems to sit there, not doing anything. I have my email open in another window, and should be seeing the new mail coming in, but no joy at all.

Holy cow this is frustrating!

Oh and in response to someone above, I'm running an older, free version of Lingon: 1.2.1 . Maybe tomorrow I will try cron.
posted by Alaska Jack at 12:17 AM on March 24, 2011

« Older Marks from blackhead tool?   |   The problem is, I googled Google in Google Chrome.... Newer »
This thread is closed to new comments.