1
votes

In my /etc/crontab file I write:

* * * * * PLACK_ENV=development -I /home/adrian/app/lib/ /home/adrian/app/script/db/log_to_db.pl 

To make a cron job run every minute. The job is running the log_to_db.pl perl script, which inserts data to my database.

When I run in my terminal PLACK_ENV=development -I /home/adrian/app/lib/ /home/adrian/app/script/db/log_to_db.pl It's OK! The script runs.

But the cron job isn't working! What can be wrong?

PD: My script starts like

    #!/usr/bin perl 
    ....

My cron log prints:

Jul  8 20:29:01 dev0001 crond[1829]: (*system*) RELOAD (/etc/crontab)
Jul  8 20:29:01 dev0001 crond[1829]: (CRON) bad username (/etc/crontab)
Jul  8 20:30:01 dev0001 crond[1829]: (*system*) RELOAD (/etc/crontab)
Jul  8 20:30:01 dev0001 crond[1829]: (CRON) bad username (/etc/crontab)
Jul  8 20:30:01 dev0001 CROND[13504]: (root) CMD (/usr/lib64/sa/sa1 -S DISK 1 1)
2
there is a space between bin and perl - Bill
@Bill unfortunately that does not seem to be the problem. i changed the shebang to #!/usr/bin/perl but nothing happens... - ado
have you actually read the error message you get in your cron log??? I'm guessing no... - pavel
it says "bad username". I guessed running this as root was not good due to the nature of script, so I add the same line in crontab -u adrian -e, and get a log: "Jul ul 8 20:53:01 dev0001 CROND[13933]: (adrian) CMD (PLACK_ENV=development perl -I /home/adrian/app/lib/ /home/adrian/app/script/db/log_to_db.pl )" But The database is not changed, not even the "last update time" column, which suggests the job isn't being done.. - ado
Isn't the path to the perl executable supposed to be in there somewhere, like before the -I? It looks like you are executing the command -I, with predictable results. - mob

2 Answers

4
votes

You need a username when putting it in the system crontab

* * * * * adrian PLACK_ENV=development -I /home/adrian/app/lib/ /home/adrian/app/script/db/log_to_db.pl

But as @jithin said, putting this in your user crontab (crontab -e) might make more sense.

2
votes

Don't edit the crontab file directly. Instead use crontab -e and add the cron entry.

With reference to the link