LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-18-2005, 10:44 AM   #1
jbob75
LQ Newbie
 
Registered: May 2004
Location: Glasgow, Scotland
Posts: 4

Rep: Reputation: 0
cron spawning extra crond - script fails


Hi,

I have searched for cron in these forums and can't seem to finds anyone who has a similar problem. Hope you can help!

I have a script called metadata.refresh that I would like to execute every five minutes. If I execute this script as root, it runs successfully, copying the webpage to local files (then cleaning up) - basically doing all it should:

Code:
#!/bin/sh
cd /root/downloads/SDSS
rm -f sdss-sites.*
rm -f sdss-trust.*
wget (website here)
wget (website here)
/usr/bin/siterefresh --out sdss-sites.xml --url (webpage)
/usr/bin/siterefresh --out sdss-trust.xml --url (webpage)
rm sdss-sites.xml
rm sdss-trust.xml
When setting up this as a cron job, I made the following crontab:

Code:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/local/metadata.refresh
When the cron job executes I get the following on ps -ef (ignorning irrelevant procs):

Code:
root     3345      1  crond
root    21654  3345 CROND
root    21655 21654 /bin/sh /usr/local/metadata.refresh
root    21656 21655 wget (1st webpage in script)
root    21657 21654 /usr/sbin/sendmail -FCronDaemon -i -odi -oem root
Why is this extra CROND process spawning (i already have a cron daemon)? I thought it was the mail part messing it up so I put MAILTO="" at the top of my crontab, then I get the same output above except the sendmail line is missing. I have tried piping the output ( /dev/null 2>&1) but this doesn nothing. I have also put an extra empty line at the end of the crontab.

I don't understand why the script runs perfectly when executed normally, but the cronjob can't complete it.

Any ideas?

Much obliged
Jbob75
 
Old 11-19-2005, 06:29 AM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,009
Blog Entries: 5

Rep: Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787
Quote:
root 3345 1 crond
root 21654 3345 CROND
Notice the CROND with PID (Process ID) 21654 has PPID (Parent Process ID) of 3345 and 3345 is the PID of crond. This means crond itself is spawning this so its not likely a problem. (Note: Case is signicant in UNIX/Linux so crond and CROND are NOT the same thing.)

The problem is most likely environmental. When a script is run from the command line it inherits the user's environment (/etc/profile, /etc/bashrc, $HOME/.profile, $HOME/.bashrc and perhaps others) so it knows full paths to commands. However when it runs from cron it does NOT inherit an environment so doesn't have full paths. Therefore one has to setup the environment in the script itself or just hard code the paths.

Instead of just rm... do /usr/bin/rm... (assuming rm is in /usr/bin - typing "which rm" will tell you where it is - I'm not in front of my Linux box at the moment).

Do same for wget. You don't need to for cd as it is an internal command of the shell.
 
Old 11-21-2005, 04:29 AM   #3
jbob75
LQ Newbie
 
Registered: May 2004
Location: Glasgow, Scotland
Posts: 4

Original Poster
Rep: Reputation: 0
jlightner

Thanks for your help! Problem solved. Script now looks like this:

Code:
#!/bin/sh

export http_proxy=(our proxy)
export HTTP_PROXY=$http_proxy
cd /root/downloads/SDSS
/bin/rm -f sdss-sites.*
/bin/rm -f sdss-trust.*
/usr/bin/wget (website here)
/usr/bin/wget (website here)
/usr/bin/siterefresh --out sdss-sites.xml --url (webpage)
/usr/bin/siterefresh --out sdss-trust.xml --url (webpage)
/bin/rm sdss-sites.xml
/bin/rm sdss-trust.xml
I put the full paths in and had to define my proxy, but after that it works a treat.

Cheers,
Jbob
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
Crond Dead But Subsys Locked, cannot restart cron services jmm8142 Linux - Software 4 05-23-2005 12:41 PM
PPPD Script problem when cron-scheduling the script andresurzagasti Linux - Networking 0 11-24-2004 02:54 PM
Extra cron jobs not in "crontab -e"? inspleak Linux - General 2 07-21-2004 09:47 PM
script does not work with crond michael_util Slackware 3 03-15-2004 02:04 PM


All times are GMT -5. The time now is 05:32 AM.

Main Menu
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