Linux – Simply status page

Sometimes there is a need for good old status page, and you are not interested in any big self-hosted frameworks, also you don’t want to create useless account just to make it on cloud service.

Why not make your own?

  1. Create basic html page as you like
  2. Create check.sh script to do the checking for you
  3. Add your script to cron
  4. Profit

 

After you create html template for status page copy the static code into check.sh and add ‘echo’ to it. The dynamic part of page need to check if the page works alright, but we will need also array in which we will store our display name of service and url to check

#!/bin/bash

echo '' > /var/www/status.html
echo '<html>' >> /var/www/status.html
echo '<head>' >> /var/www/status.html
echo '<title>status.example</title>' >> /var/www/status.html
echo '<body>' >> /var/www/status.html

arr[0]=blog
arr[1]=http://blog.example
arr[2]=www
arr[3]=http://www.example
p='UP'
r='DOWN'

for index in ${!arr[*]}
do
        if [ $(( $index % 2)) -eq 0 ]
        then
                echo '<p>' >> /var/www/status.html
                if curl -s --head ${arr[$index+1]} | head -n 1 | grep "HTTP/1.[01] [23].." > /dev/null
                then
                        echo $p >> /var/www/status.html
                else
                        echo $r >> /var/www/status.html
                fi
                echo ' ' >> /var/www/status.html
                echo ${arr[$index]} >> /var/www/status.html
                echo '</p>' >> /var/www/status.html
        fi
done

echo '</div></body></html>' >> /var/www/status.html

I assume that /var/www/status.html will serve the output of this script which is /opt/check.sh

chmod +x /opt/check.sh

 

Let us add this to cron:

crontab -e

0 * * * * /opt/check.sh

This way each hour the script will run and update status.html. Thanks to this approach we can sleep safe knowing that every hit on the page wont run the refresh command like alot of php status pages you can find on internet. We can always change the interval between refresh in cron.

Leave a Reply

Your email address will not be published. Required fields are marked *

*