Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a scheduled task that runs a shell script recurrently, and I'm having some trouble getting it to work. I give it the following command to run every minute:

~/Desktop/foo/my_script

But it doesn't ever run. (This command runs the shell script through the terminal no problem.) Any ideas what I'm doing wrong? Thanks!

Note: Here's my shell script:

#!/bin/bash
sleep 15
date >> output.txt
{ time ./foo > /dev/null ; } 2>> output.txt

And here's the cron line:

* * * * * /home/joe/Desktop/foo/my_script # JOB_ID_3
share|improve this question
1  
What scheduler are you using, and how do you know that it doesn't run? – PeterJCLaw Apr 6 '10 at 21:38
    
I'm using the scheduled tasks application from Applications -> System Tools -> Scheduled Tasks in the Ubuntu menu. I know it doesn't run, because the work isn't getting accomplished. I think this application uses cron, because I just ran the command 'crontab -e' and there's an entry for the task I created in scheduled tasks – John Kube Apr 6 '10 at 22:19
    
ah, please post the cron line. I suspect you've misunderstood (as I did at first) how it works. – PeterJCLaw Apr 6 '10 at 22:25
    
I posted it above :) – John Kube Apr 6 '10 at 22:28
up vote 0 down vote accepted

The scheduler most likely doesn't know how to expand ~ try giving it an absolute path instead.

EDIT, after solution found:

Another idea I had was that maybe cron was ignoring the line due to all *'s, but I couldn't replicate this. I did find that it's man page is rather unhelpful, but that wikipedia's page on cron is somewhat useful. I was going to suggest using the line:

*/1 * * * * /home/joe/Desktop/foo/my_script # JOB_ID_3

as this would run at */1 (ie every minute that divides by 1) if it continued to fail.

share|improve this answer
    
hmm, just tried this with cron and it seemed to work fine. – PeterJCLaw Apr 6 '10 at 21:37
    
I did, still doesn't work... – John Kube Apr 6 '10 at 21:38

I figured out the problem. Cron runs the tasks in the home directory, so that's where my output file is showing up. This is why I thought it wasn't running.

share|improve this answer
    
That's why it's a good idea to always use absolute paths for files. – Dennis Williamson Apr 6 '10 at 22:42
    
This occurred to me, but I dismissed it as too simple an issue! Though I've fallen foul of this a number of times. The other thing I was going to suggest was that you check that it was +x, but it running correctly in shell suggested that this was also not the issue. – PeterJCLaw Apr 6 '10 at 22:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .