deltascience
deltascience

Reputation: 3390

Running a crontab every 15 minutes not working on linux redhat

I want to run a crontab every 15minutes. I tried this:

0 */15 * * * ./usr/My_PATH/run.sh

But I get this error:

0 command not found 

Is there something wrong with the syntax ?

Many thanks.

UPDATE:

I corrected the script and I tried this:

*/15 * * * * /My_Path/run.sh

and this

0,15,30,45 * * * * /My_Path/run.sh

In both cases I get an error.

#1 bash: */15: No such file or directory
#2 bash: 0,15,30,45 command not found

Upvotes: 0

Views: 1696

Answers (2)

Keith Thompson
Keith Thompson

Reputation: 263557

If this:

0 */15 * * * ./usr/My_PATH/run.sh

fails with this error:

0 command not found 

then you're trying to run it as a shell command. You need to feed it to the crontab command. There are several ways to do this.

crontab -l will list the current contents of your crontab; it doesn't modify it.

crontab -e will open (a copy of) your crontab in a text editor and let you modify it. This is probably the simplest way to update it.

crontab filename reads the specified file and replaces your current crontab with its contents. (If you already have a crontab, this will quietly clobber it.)

The method I recommend is to keep a separate file containing your crontab (say, crontab.txt).

First, if you already have a non-empty crontab (check with crontab -l), save it to the file:

crontab -l > crontab.txt

Make whatever additions or other changes you want to that file, and then use

crontab crontab.txt

to install the updated crontab.

You can keep backup copies (I maintain mine in a source control system) so you can recover if you mess something up. And you can do a quick crontab -e if you want to test something, then re-run crontab crontab.txt to revert to the stored crontab.


The syntax of the crontab line in your question:

0 */15 * * * ./usr/My_PATH/run.sh

is correct, but the path ./usr/My_PATH/run.sh looks like it may be incorrect. Cron jobs run from your home directory, so the path is valid only if the usr directory is directly under your home directory (and in that case the ./ is unnecessary). It's probably better to specify the full path, which can start with $HOME/.

Upvotes: 3

Sobrique
Sobrique

Reputation: 53498

Yes.

First field is minutes. Second field is hours. You're setting it off at zero minutes past the hour, every 15th hour. So basically - 15:00 each day.

You want:

*/15 * * * * /some_script

Furthermore - ./ - it's a relative path, and that's probably a bad idea with cron, because it doesn't chdir to run stuff. Use an absolute path to avoid confusion. If you absolutely need to be in a particular directory for the script to work, you can try:

cd /path/to/script && ./this_script

So it's quite possible that you've got broken permissions or just not finding a relative path that you're using.

Upvotes: 3

Related Questions