An Easy Way To Monitor A Website From Command Line In Linux
Monitor A Website From Command Line In Linux
We all know that ping command will tell you instantly whether the website is live or down. Usually, we all check whether a website is up or down like below.
ping ostechnix.com -c 3
PING ostechnix.com (220.127.116.11) 56(84) bytes of data. 64 bytes from ostechnix.com (18.104.22.168): icmp_seq=1 ttl=51 time=376 ms 64 bytes from ostechnix.com (22.214.171.124): icmp_seq=2 ttl=51 time=374 ms --- ostechnix.com ping statistics --- 3 packets transmitted, 2 received, 33% packet loss, time 2000ms rtt min/avg/max/mdev = 374.828/375.471/376.114/0.643 ms
But, Would you run this command every time to check whether your website is live or down? You may create a script to check your website status at periodic intervals. But wait. It’s not necessary! Here is simple command that will watch or monitor on a regular interval.
watch -n 1 curl -I http://DOMAIN_NAME/
For those who don’t know, watch command is used to run any command on a particular intervals.
Let us check if ostechnix.com site is live or down. To do so, run:
watch -n 1 curl -I https://www.ostechnix.com/
Every 1.0s: curl -I https://www.ostechnix.com/ sk: Thu Dec 22 17:37:24 2016 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0 HTTP/1.1 200 OK Date: Thu, 22 Dec 2016 12:07:09 GMT Server: ApacheD Vary: Cookieh Link: <https://www.ostechnix.com/wp-json/>; rel="https://api.w.org/", <https://w p.me/5ILHv>; rel=shortlinki Content-Type: text/html; charset=UTF-8
The above command will monitor our site ostechnix.com at every one second interval. You can change the monitoring time as you wish. Unlike ping command, it will keep watching your site status until you stop it. To stop this command, press CTRL+C.
If you got HTTP/1.1 200 OK in the output, great? It means your website is working and live.
What about google?
watch -n 1 curl -I https://www.google.co.in/
Great! Google is working!
Facebook? Just run:
watch -n 1 curl -I https://www.facebook.com/
Well, Facebook is up and running too!
If it is your local website, you can cross check it by stopping your web server manually running the following commands,
If your website is running with nginx, run:
sudo systemctl stop ngix
If your website is using Apache, then you can stop as shown below.
sudo systemctl stop httpd
Now, go and check the command’s output. You will see connection refused error. Useful command, isn’t it?
This is a really handy one-liner command that you can use to monitor sites from Terminal. Also, It is quite useful when moving DNS or any other types of site migrations. It really comes in handy during high traffic events where the site going down is a strong possibility.
I know I know, this method is not opt for monitoring production and mission critical sites. There are so many free or paid tools, softwares, and apps are available in the market to watch and monitor such kind of sites. Those tools will immediately send alerts when your site is down. However, the above command is a quickest way to check your local or public website status within seconds.
Hope this helps. If you find this guide useful, please share it on your social networks and support OSTechNix.
Thanks for stopping by!
How can I benefit from this blog:
- Subscribe to our Email Newsletter : Sign Up Now
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Facebook | Twitter | Google Plus | LinkedIn | RSS feeds
Have a Good day!!