1819792 Members
3030 Online
109607 Solutions
New Discussion юеВ

Crontab query

 
Becke
Super Advisor

Crontab query


Hi Folks

I have setup simple a job in root crontab to change permission on a file every 5 minutes forever but the cron doesn't execute the script successfully, I have tried with the below entries and refreshed cron but no difference.

*/5 * * * * /script.changowner > /outputfile 2>&1

and with

0-59/5 * * * * /script.changeonwer >outputfile 2>&1

Have i got the first entry incorrect in crontab ? and what would be the correct entry ?

Thanks in advance
7 REPLIES 7
Matti_Kurkela
Honored Contributor

Re: Crontab query

When a cron job fails (or when it produces any output that is not redirected elsewhere), cron sends email to the user that owns the cron job.

So, your root account should have received email about each failed attempt. These emails might contain error messages or other clues about the failure reason.

You did not specify the name of the Linux distribution you're using, but assuming your distribution uses the Vixie Cron like most common distributions, your crontab line syntax seems OK.

However, have you really placed the script to the root directory (/) as your crontab lines seem to indicate? The recommended place to put locally-created sysadmin scripts would be /usr/local/sbin. Of course you can choose to ignore this recommendation if you have your reasons for it.

MK
MK
Kapil Jha
Honored Contributor

Re: Crontab query

you need to check a couple of things

ls -lrt /script.changeonwer
does it have execute permission.

you may out it like

*/5 **** sh /script.changowner > /outputfile 2>/tmp/test

this test file would tell you the exact error and then u can move ahead to resolve the issue.

BR,
Kapil+
I am in this small bowl, I wane see the real world......
Horia Chirculescu
Honored Contributor

Re: Crontab query

Hello,

Have you established a correct environment for the script you are using? Maybe your script fail to execute because of this.

Horia.
Best regards from Romania,
Horia.
Steven Schweda
Honored Contributor

Re: Crontab query

> [...] the cron doesn't execute the script
> successfully [...]

What, exactly, does that mean?

ls -l /script.changeonwer

cat outputfile


> ls -lrt /script.changeonwer

"rt"? Why?
Raynald Boucher
Super Advisor

Re: Crontab query

I don't know which distribution of linux you are using or if it makes a difference.

Did you try adding the user in the cron command such as:

*/5 * * * * root /script.changowner > /outputfile 2>&1

RayB


Victor Semaska_3
Esteemed Contributor

Re: Crontab query

The user field is allowed only in the system-wide crontab /etc/crontab.
There are 10 kinds of people, one that understands binary and one that doesn't.
bullz
Super Advisor

Re: Crontab query

firstly chk log in /var/log/cron

and make sure your file has execute permission for files.