LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-26-2009, 01:31 AM   #1
user1221
LQ Newbie
 
Registered: Apr 2009
Posts: 11

Rep: Reputation: 0
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?
 
Old 05-26-2009, 01:37 AM   #2
user1221
LQ Newbie
 
Registered: Apr 2009
Posts: 11

Original Poster
Rep: Reputation: 0
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.
 
Old 05-26-2009, 01:41 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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
 
Old 05-26-2009, 05:17 AM   #4
user1221
LQ Newbie
 
Registered: Apr 2009
Posts: 11

Original Poster
Rep: Reputation: 0
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.
 
Old 05-26-2009, 05:23 AM   #5
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
try to use the whole path to the commands.
 
Old 05-26-2009, 05:33 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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
 
Old 05-26-2009, 06:08 AM   #7
user1221
LQ Newbie
 
Registered: Apr 2009
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks Colucix and all,

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

Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script not running in cronjob dningale Solaris / OpenSolaris 2 08-14-2008 01:27 AM
script expression not running in cronjob dningale Solaris / OpenSolaris 2 08-13-2008 01:04 AM
cronjob xser Linux - Software 6 07-27-2008 10:38 PM
cronjob ugob Linux - Software 0 03-03-2004 10:20 AM
cronjob FastEddy Linux - General 1 04-12-2003 10:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration