LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   crontab is not working automatically (https://www.linuxquestions.org/questions/linux-newbie-8/crontab-is-not-working-automatically-751723/)

ashrash 09-01-2009 04:39 AM

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

colucix 09-01-2009 04:54 AM

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?

ashrash 09-01-2009 10:59 PM

Quote:

Originally Posted by colucix (Post 3665087)
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

chrism01 09-01-2009 11:03 PM

Post the content of the script

speck 09-01-2009 11:24 PM

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"

ashrash 09-01-2009 11:37 PM

hi this is the script
 
Quote:

Originally Posted by chrism01 (Post 3666263)
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;
~
~

colucix 09-02-2009 02:07 AM

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.

repo 09-02-2009 02:15 AM

Or look at root's mail.
Cron will sent a mail, in case of problems.

catkin 09-02-2009 02:48 AM

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).


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