Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cron and shell script

Status
Not open for further replies.

Murugs

Technical User
Jun 24, 2002
549
US
Hello All
I got cron working...But a problem
My file looks like..

40 10 * * * pg_dump testdb > junk

File "junk" is created.

when I put this
pg_dump testdb > junk
in a script "test.sh" and give the appropriate permissions and re-edit my crontab field as
40 10 * * * test.sh
cron is not running...any suggestions..

regards
MP
 
A job scheduled in cron has no environment, so maybe it doesn't know where test.sh is. Maybe it finds test.sh, but doesn't know what pg_dump is. Either do

40 10 * * * su - myusername -c test.sh

Or use absolute paths in the ron entry and your script.

Greg.
 
Hello Greg
I have used absolute path in my crontab entry and in my shell script and still same status...

regards
MP
 
Hmmm .. make sure you also have all the necessary environment variables set up in your script.

Greg.
 
Your script is starting with the #!/usr/bin/ksh for example or #!/usr/bin/sh right? Can you run the script from the command line without any problems? Do you put sh ${SCRIPT} or just type the name? If you don't have a environment script setup to detail your paths and what not, does your script make use of absolute path names?

I.E. /usr/bin/find /tmp/ | /usr/bin/grep -c err* > ${DIR}/err.dat, where ${DIR} is some directory.

Also, you have to put the absolute path in your crontab to my knowledge, otherwise if you have this under the root crontab for instance and that script isn't in the root directory, then it isn't going to run.

Have you setup a log file as well for errors?

I.E. 40 10 * * * /home/${NAME}/${FILE} > /var/adm/log/junk 2> /var/adm/log/errjunk

Does this help?
 
Hello
Finally I got it working...
Yes I think the problem was in the shell part..
i.e my file now looks like

#! /bin/sh
and my command here...

everything went fine.
Thanks for the suggestions..

regards
MP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top