LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Bash script not running within crontab job (https://www.linuxquestions.org/questions/linux-general-1/bash-script-not-running-within-crontab-job-522051/)

WrightExposure 01-23-2007 10:27 AM

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

hepburnenthorpe 01-23-2007 10:35 AM

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?

WrightExposure 01-23-2007 10:45 AM

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

WrightExposure 01-23-2007 06:28 PM

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


All times are GMT -5. The time now is 08:12 PM.