| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Senior Member | restart httpd on fail I'm using this script (I think I got it off of WHT) to restart httpd whenever a file failed to download on my server. Code: #!/bin/bash
FILE=http://www.domain.tld/test.file
rm -f test.file
wget -q $FILE -O test.file
if [ ! -f test.file ]
then
/etc/init.d/httpd restart
echo 'ALERT - HTTPD restarted on:' `date` | mail -s "Alert: HTTPD Restarted" user@domain.tld
fi
exit $?
Code: */5 * * * * /bin/nfup > /dev/null 2>&1 Is there anything wrong with the script? Thanks |
| |
| | #2 (permalink) |
| NamePros Regular | I'm guessing you don't have write permissions for test.file, wherever your script is trying to dump it. Add an absolute path to a location where you have write permissions. Code: rm -f /path/you/can/write/to/test.file wget -q $FILE -O /path/you/can/write/to/test.file if [ ! -f /path/you/can/write/to/test.file ] |
| |
| | #3 (permalink) |
| Senior Member | It is also possible that the user running the script does not have permissions to restart the service (you could see what user is running the process by doing a whoami command within the script). Out of interest why are you using a php script, why not just use a bash script?
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft |
| |
| | #4 (permalink) |
| Senior Member | The cron was running as ROOT and i've seen the file show up before. Someone on WHT suggested I use this: Code: #!/bin/sh FILE=http://www.domain.tld/test.file wget -q $FILE if [ ! -f test.file ] then /etc/init.d/httpd restart echo 'ALERT - HTTPD restarted on:' `date` | mail -s "Alert: HTTPD Restarted" user@domain.tld fi rm -rf test.file* edit: isn't this running on bash? |
| |
| | #5 (permalink) |
| Senior Member | that looks like it will be a better opting than using a php script.
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft |
| |
| | #6 (permalink) |
| NamePros Regular | If it's still not working, try sending the output to a file in some writeable directory (instead of /dev/null) so you can see any errors it spits out: */5 * * * * /bin/nfup > /tmp/somefilename 2>&1 If it's a cron issue, most cron problems are usually either paths, environments or permissions. Cron runs with a limited environment, not the user's standard login environment so things need to be spelled out in your script. Once you get this running, I hope next thing on the agenda is to try to find out why httpd is crashing ? Sounds like you have much worse problems than getting this script to run! Last edited by enlytend; 08-05-2007 at 03:59 PM. |
| |
| | #7 (permalink) |
| Senior Member | Talked it over on a few forums and came up with this: Code: #!/bin/bash
tmp_file="/home/user/test_file"
wget -t 1 -T8 -O $tmp_file http://www.domain.tld/file.html >> /dev/null 2>&1
test=`grep OK $tmp_file`
if [ "$test" == "" ]; then
#echo "File download failed, assuming offline."
/etc/init.d/httpd restart
echo 'ALERT - HTTPD restarted on:' `date` | mail -s "Alert: HTTPD Restarted" you@domain.tld
elif [ "$test" == "<html>OK</html>" ]; then
echo "HTTPD seems to be OK" >> /dev/null 2>&1
else
#echo "Unknown error..."
echo 'ALERT - HTTPD had an unkown error on:' `date` | mail -s "Alert: HTTPD Error" you@domain.tld
fi
rm -rf $tmp_file
Note: file.html should contain Code: <html>OK</html> Last edited by Crusader; 08-05-2007 at 11:15 PM. Reason: additional |
| |
| | #8 (permalink) | |
| NPQ's PA, Slave, and On Call Coder Technical Services | Quote:
__________________ | |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |