LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   crontab and a bash script (https://www.linuxquestions.org/questions/linux-general-1/crontab-and-a-bash-script-700236/)

seefor 01-27-2009 10:23 AM

crontab and a bash script
 
I've add the following via crontab -e:
Quote:

15 9 * * * /hunter/ngc/start.sh

here is the shell script:
Quote:

#!/bin/bash
/hunter/ngc/./gather.sh
/hunter/ngc/./trans_csv.sh
/hunter/ngc/./db_reload.sh
Here is the output from /var/log/cron:
Quote:

Jan 27 09:15:00 crbc-tacacs-1 CROND[9083]: (root) CMD (/mcasthunter/ngc/start.sh)
The script does not run even thought it states it does.
start.sh runs fine from a command line

Not sure what else to try :scratch::scratch:

Thanks in advance.
SeeFor

colucix 01-27-2009 10:38 AM

Are all the scripts made executables? Try to look at the mail of the crontab owner (root), since any standard output or any standard error coming from a cron job (and not explicitly redirected to a file) is sent there. You may find some useful hint about what's coming up.

seefor 01-27-2009 11:01 AM

Quote:

Subject: Cron <root@crbc-tacacs-1> /mcasthunter/ngc/start.sh
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>

/hunter/ngc/start.sh: line 2: ./gather.sh: No such file or directory
/hunter/ngc/start.sh: line 3: ./trans_csv.sh: No such file or directory
/hunter/ngc/start.sh: line 4: ./db_reload.sh: No such file or directory
I just change it to:
Quote:

#!/bin/bash
/hunter/ngc/./gather.sh
/hunter/ngc/./trans_csv.sh
/hunter/ngc/./db_reload.sh
This morning!

Today so hopefully tomorrow it will run :o

Thanks for you help, with checking mail idea.
How do I make it out to a file in crontab, so it would be easier to look for it?

Thanks,
Sif

repo 01-27-2009 11:07 AM

Quote:

/hunter/ngc/./gather.sh
just change it to

Code:

/hunter/ngc/gather.sh
You need to give the full path.
or first cd to the directory
Code:

cd /hunter/ngc
./gather.sh

Quote:

Today so hopefully tomorrow it will run
Why don't you run the script manually?
put it in your root directory and run it

seefor 01-27-2009 11:19 AM

Thanks, I will cd to the directory and give that a try.

We make changes to the all the devices in our network druing 2300 to 0700. I need it to gather all the data every morning at 9:15 AM, then a php script compares the past two days and generate a report to management morning of all the changes.

Thanks again

repo 01-27-2009 11:22 AM

Code:

/hunter/ngc/./gather.sh
just remove the ./
Code:

/hunter/ngc/gather.sh
./ is to execute when you are in the directory, and it is not in the path.
So just give the whole path to the command

colucix 01-27-2009 03:41 PM

Quote:

Originally Posted by seefor (Post 3422921)
How do I make it out to a file in crontab, so it would be easier to look for it?

If you do not them sent by mail, just redirect both standard output and standard error to a file, directly from the crontab entry:
Code:

15 9 * * * /hunter/ngc/start.sh >> $HOME/cron.log 2>&1
The double redirection >> will append the output to the log file progressively.


All times are GMT -5. The time now is 06:15 AM.