Hi, I'm looking to write a shell script that will ping port 80 of localhost
If port 80 is closed then the script should send an email to email warning that apache has crashed.
Can anyone help point me in the right direction?
Hi, I'm looking to write a shell script that will ping port 80 of localhost
If port 80 is closed then the script should send an email to email warning that apache has crashed.
Can anyone help point me in the right direction?
This will try to send a GET request to 127.0.0.1 at port 80, if there is no reply it will run the script found at "/path/to/emailing/script"Code:echo -n "GET / HTTP/1.0\r\n\r\n" | nc 127.0.0.1 80 || /path/to/emailing/script
Schedule it as a cron job.
Hope this helps...
Great solution very nice and simple. But wouldn't you want echo to interprate the escapes? If I'm right then this might be the correct way.
I could be wrong.Code:echo -e "GET / HTTP/1.0\r\n\r" | nc 127.0.0.1 80 || /path/to/emailing/script
Edit:
Another possibility...
Code:echo GET / | nc 127.0.0.1 80
Last edited by bashologist; April 28th, 2011 at 10:07 PM.
...
Code:netstat -tupln | grep :80
Bookmarks