trouble using a scheduled task to run a shell script (ubuntu linux)

1

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

John Kube

Posted 2010-04-06T21:28:48.443

Reputation: 219

1What scheduler are you using, and how do you know that it doesn't run? – PeterJCLaw – 2010-04-06T21:38:27.457

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 – 2010-04-06T22:19:41.370

ah, please post the cron line. I suspect you've misunderstood (as I did at first) how it works. – PeterJCLaw – 2010-04-06T22:25:28.797

I posted it above :) – John Kube – 2010-04-06T22:28:41.927

Answers

0

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.

PeterJCLaw

Posted 2010-04-06T21:28:48.443

Reputation: 1 882

hmm, just tried this with cron and it seemed to work fine. – PeterJCLaw – 2010-04-06T21:37:58.160

I did, still doesn't work... – John Kube – 2010-04-06T21:38:20.920

0

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.

John Kube

Posted 2010-04-06T21:28:48.443

Reputation: 219

That's why it's a good idea to always use absolute paths for files. – Paused until further notice. – 2010-04-06T22:42:25.323

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 – 2010-04-06T22:45:58.170