| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: Aug 2003 Location: Canada
Posts: 1,257
![]() ![]() ![]() ![]() | 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 $? ????: NamePros.com http://www.namepros.com/programming/357862-restart-httpd-on-fail.html Code: */5 * * * * /bin/nfup > /dev/null 2>&1 Is there anything wrong with the script? Thanks
__________________ Near Fantastica | Matthew Good - Vancouver TS Design Group - Vancouver, BC based Graphic Design >> Do you Frawlik? << |
| |
| | #2 (permalink) |
| NamePros Regular Join Date: May 2004 Location: NYC
Posts: 236
![]() ![]() ![]() | 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. ????: NamePros.com http://www.namepros.com/showthread.php?t=357862 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) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |
| | THREAD STARTER #4 (permalink) |
| Senior Member Join Date: Aug 2003 Location: Canada
Posts: 1,257
![]() ![]() ![]() ![]() | 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* ????: NamePros.com http://www.namepros.com/showthread.php?t=357862 edit: isn't this running on bash?
__________________ Near Fantastica | Matthew Good - Vancouver TS Design Group - Vancouver, BC based Graphic Design >> Do you Frawlik? << |
| |
| | #5 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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) |
| Forum Moderator ![]() Join Date: Aug 2006 Location: USA
Posts: 2,036
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 04:59 PM.
|
| |
| | THREAD STARTER #7 (permalink) |
| Senior Member Join Date: Aug 2003 Location: Canada
Posts: 1,257
![]() ![]() ![]() ![]() | 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 ????: NamePros.com http://www.namepros.com/showthread.php?t=357862 Note: file.html should contain Code: <html>OK</html>
__________________ Near Fantastica | Matthew Good - Vancouver TS Design Group - Vancouver, BC based Graphic Design >> Do you Frawlik? <<
Last edited by Crusader; 08-06-2007 at 12:15 AM.
Reason: additional
|
| |
| | #8 (permalink) | ||||
| Senior Member Join Date: Mar 2005
Posts: 4,948
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
| ||||
| |