Peter Hayek
Peter Hayek

Reputation: 37

running a script in crontab

I have a very simple script in my crontab that I want to run every day. It is located in /home:

-rwxr-xr-x 1 root        root     40 Apr 15 08:01 kill_slony_stop_sql.sh

It has execute permission and here is the content:

#!/bin/bash
slon_kill;rcpostgresql stop

and here is the cron line for it to run daily:

56 12 * * * /home/kill_slony_stop_sql.sh

But it is not working for some reason. When I type /home/kill_slony_stop_sql.sh in the command line, it works good but it is not working in the crontab.

Any thoughts?

Upvotes: 1

Views: 369

Answers (2)

PaulM
PaulM

Reputation: 32

I had the same problem with a daily cron job, I used the @daily but this will run at 00:00 every day.

@daily /usr/local/bin/msa70_check.sh

was the cron tab line i added, below is the script i run.

#!/bin/bash
# msa70 disk check
/sbin/mdadm --detail /dev/md0 /dev/md1|
/bin/mailx -s"Disk check on server123 please check" [email protected]

I also had to edit my script and add /sbin/ and /bin in front of mdadm and mailx for the cron job to run

Upvotes: 0

Tristan Foureur
Tristan Foureur

Reputation: 1657

It is most likely a PATH issue. Have a look at Why is my crontab not running and be sure to set a PATH so that it can call your slon_kill command.

Also, add some debug to your cron

56 12 * * * /home/kill_slony_stop_sql.sh &>/tmp/errorcron.log

And also look at the logs; cron logs its actions via syslog, which (depending on your setup) often go to /var/log/cron or /var/log/syslog.

Upvotes: 1

Related Questions