LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 09-01-2009, 04:39 AM   #1
ashrash
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Rep: Reputation: 0
crontab is not working automatically


hi guys,,


i m new to this forum ..and i m not linux guy,but little bit i know linux

right now i m using linux version

Linux version 2.6.9-89.ELsmp (mockbuild@hs20-bc1-2.build.redhat.com) (gcc version 3.4.6 20060404 (Red Hat 3.4.6-11))

and one more thing before posting my question i have serached all the solution to my problem ,,but not solved
i have script file in crontab

which is not running automatically but manually it is running .....

by this command i m trying to see crontab is running or not

yes it running at every 5 min
tail -f /var/log/cron

Sep 1 14:40:01 localhost crond[6478]: (root) CMD (/opt/scheduler/myprogram.sh)
Sep 1 14:45:01 localhost crond[6648]: (root) CMD (/opt/scheduler/myprogram.sh)

but nothing is happening

actually i m trying to update a table every 5 minutes if i do using crontab uatomatically it wont run ,but manually if i run in linuc comman d prompt tables gets updated



please help me if anyone is familair with this type of problem

thanks
 
Old 09-01-2009, 04:54 AM   #2
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
Yes, it is a common problem if you don't do some trick to run a script by crontab. Take in mind that the cron environment is very different from your usual login environment. Anyway, here is the questions:

1. Have you checked the standard output and the standard error coming from the cron job? If you did not redirect them to a file, most likely they have been sent to you by mail (that one you can see using the mail command from a terminal), since this is the default behaviour.

2. What is the actual crontab entry?

3. Can you post the actual content of the script or at least describe the desired output?
 
Old 09-01-2009, 10:59 PM   #3
ashrash
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
Yes, it is a common problem if you don't do some trick to run a script by crontab. Take in mind that the cron environment is very different from your usual login environment. Anyway, here is the questions:

1. Have you checked the standard output and the standard error coming from the cron job? If you did not redirect them to a file, most likely they have been sent to you by mail (that one you can see using the mail command from a terminal), since this is the default behaviour.

2. What is the actual crontab entry?

3. Can you post the actual content of the script or at least describe the desired output?
hi thanks for replying sorry for late reply

i have checked the error but there is no error

2nd the crontab entry contains

*/5 * * * * /opt/scheduler/myprogram.sh

in this script i m calling a procedure which in turn updating the table

thats it

manually it is running but if i put in crontab it is not running

i dont know what is the problem
please help me
 
Old 09-01-2009, 11:03 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,396

Rep: Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395
Post the content of the script
 
Old 09-01-2009, 11:24 PM   #5
speck
Member
 
Registered: Nov 2001
Location: US
Distribution: Slackware 14.2
Posts: 354

Rep: Reputation: 93
One simple thing to check in your scripts is to make sure you're using the full path to the command. This is true for every executable in your script.

Bad
Code:
wget "http://www.google.com"
Good
Code:
/usr/bin/wget "http://www.google.com"
 
Old 09-01-2009, 11:37 PM   #6
ashrash
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Original Poster
Rep: Reputation: 0
hi this is the script

Quote:
Originally Posted by chrism01 View Post
Post the content of the script

#!bin/bash
#. /$HOME/.bash_profile

db2 connect to dbprod user db2inst1 using db2inst1;

db2 call product.productupdate_auto;

db2 connect reset;
~
~
 
Old 09-02-2009, 02:07 AM   #7
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
1. Replace the command db2 with its full path /path/to/db2 as speck suggested above
2. Modify the crontab entry to:
Code:
*/5 * * * * /opt/scheduler/myprogram.sh >> $HOME/cron.log 2>&1
then check the file $HOME/cron.log to see if you get some message from the job.
 
Old 09-02-2009, 02:15 AM   #8
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Or look at root's mail.
Cron will sent a mail, in case of problems.
 
Old 09-02-2009, 02:48 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
speck's advice is good. A quick-and-dirty workaround is to change #!/bin/bash to #!/bin/bash -l (that's a letter l) to ask bash to run the log in process. This can be especially useful when environment variables are required as is often the case for database work. The commented out . /$HOME/.bash_profile suggests you have tried to simulate log in already (it may not have worked because log in sources more files than .bash_profile alone).
 
  


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
Crontab not working Zeno McDohl Linux - Newbie 4 10-08-2008 05:55 PM
crontab not working ankitsagwekar Red Hat 1 08-08-2008 05:45 AM
Crontab fails automatically Sriram.root AIX 3 07-21-2008 01:26 AM
Crontab Not working appropriate? roclok Linux - Software 9 06-15-2006 11:34 PM
crontab nor working navaladi Mandriva 11 01-17-2005 06:58 AM

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

All times are GMT -5. The time now is 12:16 AM.

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