LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cronjob not running! (https://www.linuxquestions.org/questions/linux-newbie-8/cronjob-not-running-728501/)

user1221 05-26-2009 12:31 AM

cronjob not running!
 
Hi Guyz,

I created a cronjob in Linux 2.6 but it is not triggering at the specified time,
The crontab entry is like this.
-------------------------
#Sheduled backup job.
#Backup the database [ daily at midnight ]
3 2 * * * ~/db.sh 2>&1 >> ~/_backup/db.log
-------------------------------------------

The background process crond is also running.

[root@cc1001-ehealth cron.daily]# ps -ef | grep cron
root 3044 1 0 May12 ? 00:00:00 crond
root 3731 28629 0 08:20 pts/1 00:00:00 grep cron

PLEASE help, what to do to run a script using cron job?

user1221 05-26-2009 12:37 AM

The script is running fine when fired manually. The script is also running from the other user accounts cronjob. I want to run the script from the root user account, I copied the script to root user's home and then created the cronjob but the script is not triggering at the given time.

Tinkster 05-26-2009 12:41 AM

Hi, welcome to LQ!

db.sh & comments suggest database involvement ... Is there anything in the
other user accounts environment set that roots account is missing?



Cheers,
Tink

user1221 05-26-2009 04:17 AM

Yes the script is taking the backup of mySql database and everything related to the database is provided in the script. The same script is running from other user account and no environment settings are used for that. And also from the root user the script is running when fired manually but not from the cronjob. I want to run the script from root user's cronjob. The job is not even triggering. Please tell me whether I am missing something?

Thanks & Regards.

repo 05-26-2009 04:23 AM

try to use the whole path to the commands.

colucix 05-26-2009 04:33 AM

Code:

3 2 * * * ~/db.sh 2>&1 >> ~/_backup/db.log
Note that the order of redirection is important: in this crontab entry the standard error is redirected to the standard output, when the standard output still points to the terminal. In this way the standard error is not redirected to the file db.log. At this point you can check the root's mail to see if cron has sent any standard error via mail to the crontab's owner (default behavior).

Then just reverse the two redirections in order to have both stdout and stderr sent to the log file:
Code:

3 2 * * * ~/db.sh >> ~/_backup/db.log 2>&1

user1221 05-26-2009 05:08 AM

Thanks Colucix and all,

I changed the standard error redirection as suggested by Colucix and it worked.

Thanks.


All times are GMT -5. The time now is 06:10 PM.