LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-10-2007, 08:35 AM   #1
dinoman1989
LQ Newbie
 
Registered: May 2005
Posts: 6

Rep: Reputation: 0
Weird interaction between wget and cron


Hi,

I've written a cron script to monitor a website for downtime. Essentially it wgets the website, greps it for a known string, and if the string doesn't show up, emails me. It also has a check to make sure it emails me at most once an hour, so my box doesn't fill up:

Code:
 #!/bin/sh
rm runlast
date >> runlast

y="The following services on OpenMRS.org are broken!  Oh noes!  "
z=0

wget demo.openmrs.org -O openmrs1.html
x=`cat openmrs1.html|grep /openmrs/dwr/interface/DWRAlertService.js`
if [ ! -n "$x" ]
then
y=$y"demo.openmrs.org "
z=1
fi

wget openmrs.org -O openmrs2.html
x=`cat openmrs2.html|grep Meeting,Community,Developers,Developers`
if [ ! -n "$x" ]
then
y=$y"openmrs.org "
z=1
fi

wget dev.openmrs.org -O openmrs3.html
x=`cat openmrs3.html|grep /wiki/WikiStart?action=diff`
if [ ! -n "$x" ]
then
y=$y"dev.openmrs.org "
z=1
fi

wget forum.openmrs.org -O openmrs4.html
x=`cat openmrs4.html|grep templates/subSilver/images/openmrs-small-logo.gif`
if [ ! -n "$x" ]
then
y=$y"forum.openmrs.org "
z=1
fi


if test $z -eq 1
then
a=`cat olddate`
b=`perl -le 'print time'`
c=`expr $b - $a`
echo `date`" "$y$c >> openmrslog
        if test $c -ge 3600
        then
        rm olddate
        echo $b >> olddate
        echo $y | mail me@me.com
        fi
fi
The script works when run via ssh, but when run via cron it emails me, but the wgets fail. That is, if the correct files are already there, it will not email me regardless of whether the website is down: it doesn't try to fetch them! Along the same line, if the correct files aren't already there (eg openmrs1.html, openmrs2.html... aren't there), then it will not try to download them, and will just email me. I don't understand this -- why does it work via ssh, but not cron, and, more importantly, how can I fix it?!

My crontab -l output is:
Code:
0,10,20,30,40,50 * * * * /u/1/a/ata2114/openmrs.sh>/dev/null 2>&1
Any help would be appreciated!

Adam
 
Old 07-10-2007, 10:09 AM   #2
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,501
Blog Entries: 2

Rep: Reputation: 68
My first guess is maybe there is no PATH to wget, perl or other program you call in your script; the environment in a cronjob is not the same as is in a interactive shell.

To check, remove the redirections in the cronjob, to get the output and errors to help to diagnose the problem.

Last edited by marozsas; 07-10-2007 at 10:23 AM.
 
Old 07-11-2007, 02:29 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,365

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
cron doesn't have hardly any shell vars or PATH (by default) unless you set them, so always specify complete dirpaths to all progs and files.
Incidentally cron usually emails root if it has a problem.
 
  


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
setting up a php cron using wget Roosta21 Linux - Software 1 04-18-2007 06:29 AM
console interaction in C? PatrickNew Programming 8 01-24-2007 11:17 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 01:57 AM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 01:50 PM
weird complain from wget jiawj Red Hat 3 10-18-2004 12:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:25 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