LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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-23-2007, 10:27 AM   #1
WrightExposure
LQ Newbie
 
Registered: Dec 2006
Posts: 12

Rep: Reputation: 0
Bash script not running within crontab job


Hi all,

I think I might have found my answer from another post but I still want to run this by everybody first just in case I should be checking something else also.


I have a bash script written to go out and run perl script that collects data from a couple sensors then is supposed to populate a mysql database.

This script runs perfectly from the command line but will not function from a crontab job.

Below is a copy of the script and a copy of the crontab. From the other post it looks like I need to change the #! /bin/bash to #! /bin/sh is this correct? I'm logged in as root by the way and its being run on FC5.

Bash script:

#! /bin/bash
# script to run the digitemp_mysql.pl program

cd /root/digitemp-3.5.0/perl/
.//digitemp_mysql.pl



Cron job:

1 * * * * /root/digitemp-3.5.0/perl/digitemp_my_sql


Thank you for your assistance in advance.

Mark
 
Old 01-23-2007, 10:35 AM   #2
hepburnenthorpe
Member
 
Registered: Jun 2006
Location: Sydney
Distribution: Gentoo + Debian
Posts: 132

Rep: Reputation: 15
Quote:
From the other post it looks like I need to change the #! /bin/bash to #! /bin/sh is this correct?
No. But anytime you are writting a script to be run via cron you should always use full paths to each command. Cron may not have the same $PATH as a normal user. In fact I normally unset the $PATH variable first thing, just to make sure I wont try and rely on it.

eg; Instead of...

Code:
cd /root/digitemp-3.5.0/perl/
you would need to use...

Code:
/bin/cd /root/digitemp-3.5.0/perl/
Im not sure why your not just running this Perl script striaght from cron though? Why do you need the bash script at all?

Last edited by hepburnenthorpe; 01-23-2007 at 10:37 AM.
 
Old 01-23-2007, 10:45 AM   #3
WrightExposure
LQ Newbie
 
Registered: Dec 2006
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by hepburnenthorpe
No. But anytime you are writting a script to be run via cron you should always use full paths to each command. Cron may not have the same $PATH as a normal user. In fact I normally unset the $PATH variable first thing, just to make sure I wont try and rely on it.

eg; Instead of...

Code:
cd /root/digitemp-3.5.0/perl/
you would need to use...

Code:
/bin/cd /root/digitemp-3.5.0/perl/
Im not sure why your not just running this Perl script striaght from cron though? Why do you need the bash script at all?
I was also running into problems getting the perl script to run from cron also LOL. I wanted to try running it as a script then have the script run from cron. I have no issue running it directly if I could get it to. the command I was giving cron was: /root/digitemp-3.5.0/perl/perl digitemp_mysql.pl

Any thoughts on this is also appriciated. As you probably guess I'm a real newbie to all this linux and script stuff.

Mark
 
Old 01-23-2007, 06:28 PM   #4
WrightExposure
LQ Newbie
 
Registered: Dec 2006
Posts: 12

Original Poster
Rep: Reputation: 0
Figured out why I wasn't getting the crontab job to run every minute like I wanted. I thought 1 * * * * would run every minute not one minute past every hour.

After discovering I had 9 hours of data recorded today when I got home I noticed they were all stored at XX:01. I looked at the cron instructions a litte more and figured out what I really wanted was 0-59 0-23 * * * (command).

Thanks to everybody who looked at the post!!

Being new to linux is so much fun LOL

Mark

Last edited by WrightExposure; 01-23-2007 at 06:34 PM.
 
  


Reply



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
Bash script and cron job rust8y Linux - General 2 07-08-2006 07:45 AM
Using crontab in a bash script nro Linux - Newbie 3 08-26-2005 08:04 PM
error running script on crontab haora Linux - Newbie 3 03-11-2005 04:02 PM
bash script for database searching using crontab saurya_s Linux - Software 5 01-22-2004 08:53 AM
adding a job to crontab via shell script tazio Linux - General 7 10-23-2003 02:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:59 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
Open Source Consulting | Domain Registration