nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Cron to check a website and restart it if down

This is a discussion on Cron to check a website and restart it if down within the Shell scripting forums, part of the Development/Scripting category; hi, #!/bin/sh wget website.com -o /tmp/web value=`cat /tmp/web |grep OK | nl|awk '{print$1}'` if [ $value -eq '' ] then ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 05-16-2008, 04:54 PM
Junior Member
User
 
Join Date: May 2008
My distro: fedora
Posts: 17
Rep Power: 0
permalac is on a distinguished road
Default Cron to check a website and restart it if down

hi,


Quote:
#!/bin/sh

wget website.com -o /tmp/web
value=`cat /tmp/web |grep OK | nl|awk '{print$1}'`

if [ $value -eq '' ]
then

restart service
fi
and on cron i launch it each 15 minutes


but I know there are better ways to do that

whats your way?


Thanks
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-16-2008, 05:42 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 910
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Code:
#!/bin/sh
# Apache Process Monitor
pgrep httpd
if [ $? -eq 0 ]
then
 # restart apache
 service httpd restart
fi
Save script monitorhttpd.sh. Next set cronjob


Code:
 */5 * * * * sh /path/to/monitorhttpd.sh >/dev/null 2>&1
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #3 (permalink)  
Old 05-16-2008, 06:19 PM
Junior Member
User
 
Join Date: May 2008
My distro: fedora
Posts: 17
Rep Power: 0
permalac is on a distinguished road
Default

I like yours more than mine, .. still i'll paste it here for global interest.

Quote:
#!/bin/sh

URL=site.es

lynx -dump "$URL" > /dev/null 2> /dev/null

EXITCODE=$?

if [ "$EXITCODE" -eq "0" ]
then
echo "OK"
else
# echo "ERROR: $EXITCODE"
/opt/www/site.es/bin/zopectl restart
fi

exit 0
Reply With Quote
  #4 (permalink)  
Old 05-16-2008, 06:41 PM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 557
Rep Power: 6
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default FreeBSD Apache Auto Restart Shell Script If it Gotes Down

nice work, here my script from bsd box

Code:
#!/bin/sh
isAlive=`ps ax | grep -v grep | grep -c httpd`
if [ $isAlive -le 0 ]
then
/usr/local/etc/rc.d/apache restart
fi
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
Reply

Bookmarks

Tags
apache script , shell script


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Tomcat shell script cron job to restart server kasimani Shell scripting 4 05-03-2008 07:46 PM
How to host website using adsl router zeebala CentOS / RHEL / Fedora 2 04-01-2008 09:23 PM
How to host website using adsl router zeebala CentOS / RHEL / Fedora 0 11-29-2007 07:15 PM
Cron job on Fedora 7 angenet Linux software 1 10-04-2007 05:11 PM
Cron problem vin6384 Linux software 1 03-08-2006 09:48 PM


All times are GMT +5.5. The time now is 05:10 PM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36