LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 01-27-2009, 11:23 AM   #1
seefor
Member
 
Registered: Mar 2006
Posts: 34

Rep: Reputation: 15
Question 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

Thanks in advance.
SeeFor
 
Old 01-27-2009, 11:38 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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.
 
Old 01-27-2009, 12:01 PM   #3
seefor
Member
 
Registered: Mar 2006
Posts: 34

Original Poster
Rep: Reputation: 15
Thumbs up

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

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
 
Old 01-27-2009, 12:07 PM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Linux Mint
Posts: 8,516

Rep: Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896
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

Last edited by repo; 01-27-2009 at 12:19 PM.
 
Old 01-27-2009, 12:19 PM   #5
seefor
Member
 
Registered: Mar 2006
Posts: 34

Original Poster
Rep: Reputation: 15
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

Last edited by seefor; 01-27-2009 at 12:24 PM.
 
Old 01-27-2009, 12:22 PM   #6
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Linux Mint
Posts: 8,516

Rep: Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896
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
 
Old 01-27-2009, 04:41 PM   #7
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Quote:
Originally Posted by seefor View Post
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.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
removing # from crontab (bash script) inderpunj Programming 4 10-13-2008 03:34 PM
Crontab/bash: a console script to make just a 2-3 sec ring to a fixe phone ? frenchn00b Programming 10 04-27-2008 02:37 PM
Bash script not running within crontab job WrightExposure Linux - General 3 01-23-2007 07:28 PM
Using crontab in a bash script nro Linux - Newbie 3 08-26-2005 09:04 PM
bash script for database searching using crontab saurya_s Linux - Software 5 01-22-2004 09:53 AM


All times are GMT -5. The time now is 12:37 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration