Check of the services are online

I have written a script that checks whether the services are still running, if not, I will receive an email and can take action. The script writes the data in a file. This file is in /var/www/up and is called up.htm. Now I can view the file via the browser. http://ip-adres/up/up.htm

http://gw.pd2lt.ampr.org/up/up.htm  # Only amprnet

I have add a cronjob for it. The cronjob runs the script every 5 minutes

*/5  *    * * *   root    /usr/local/etc/ax25/ax-up

The output look like this

Here is the script

#!/bin/sh
mail=pd2lt( @ )packet-radio.net;
S1=netromd;
S2=ax25d;
S3=ax25rtd;
S4=flexd;
S5=mheardd;
S6=beacon;
S7=xfbbd;
S8=jnos;
S9=linuxnet;
S10=ax25ipd;
S11=ax25udp;
S12=rstatrxd;
S13=slattach;
S14=socat;
S15=kissnetd;
S16=kissattach;
S17=apache2;

# Remove the old one
rm -f /var/www/up/up.htm
    echo "<h2> Check services on pi1lap/pi8lap</h2>" >> /var/www/up/up.htm
    echo "#########################################<br/>" >> /var/www/up/up.htm
    echo "Services check script v2.0.32<br/>" >> /var/www/up/up.htm
    echo "E-mail : pd2lt@packet-radio.net<br/>" >> /var/www/up/up.htm
    echo "https://packet-radio.net<br/>" >> /var/www/up/up.htm
    echo "#########################################<br/><br/>" >> /var/www/up/up.htm
    echo "Uptime Pi1lap -" `uptime` "<br/>" >> /var/www/up/up.htm
    echo `uname -a` "<br/><br/>" >> /var/www/up/up.htm
# netromd
if P1=$(pgrep $S1)
then
    echo "1. $S1 is up and running, PID is $P1 - Uptime" `ps -o etime= -p "$P1"` "<br/>" >> /var/www/up/up.htm
else
    echo "1. $S1 is not running" | mail -s "$S1 down" $mail
fi
# ax25d
if P2=$(pgrep $S2)
then
    echo "2. $S2 is up and running, PID is $P2 - Uptime" `ps -o etime= -p "$P2"` "<br/>" >> /var/www/up/up.htm
else
    echo "2. $S2 is not running" | mail -s "$S2 down" $mail
fi
# ax25rtd
if P3=$(pgrep $S3)
then
    echo "3. $S3 is up and running, PID is $P3 - Uptime" `ps -o etime= -p "$P3"` "<br/>" >> /var/www/up/up.htm
else
    echo "3. $S3 is not running" | mail -s "$S3 down" $mail
fi
# flexd
if P4=$(pgrep $S4)
then
    echo "4. $S4 is up and running, PID is $P4 - Uptime" `ps -o etime= -p "$P4"` "<br/>" >> /var/www/up/up.htm
else
    echo "4. $S4 is not running" | mail -s "$S4 down" $mail
fi
#mheardd
if P5=$(pgrep $S5)
then
    echo "5. $S5 is up and running, PID is $P5 - Uptime" `ps -o etime= -p "$P5"` "<br/>" >> /var/www/up/up.htm
else
    echo "5. $S5 is not running" | mail -s "$S5 down" $mail
fi
# beacon
if P6=$(pgrep $S6)
then
    echo "6. $S6 is up and running, PID is $P6 <br/>" >> /var/www/up/up.htm
else
    echo "6. $S6 is not running" | mail -s "$S6 down" $mail
fi
# xfbbd
if P7=$(pgrep $S7)
then
    echo "7. $S7 is up and running, PID is $P7 - Uptime" `ps -o etime= -p "$P7"` "<br/>" >> /var/www/up/up.htm
else
    echo "7. $S7 is not running" | mail -s "$S7 down" $mail
fi
# jnos
if P8=$(pgrep $S8)
then
    echo "8. $S8 is up and running, PID is $P8 - Uptime" `ps -o etime= -p "$P8"` "<br/>" >> /var/www/up/up.htm
else
    echo "8. $S8 is not running" | mail -s "$S8 down" $mail
fi
# linuxnet
if P9=$(pgrep $S9)
then
    echo "9. $S9 is up and running, PID is $P9 - Uptime" `ps -o etime= -p "$P9"` "<br/>" >> /var/www/up/up.htm
else
    echo "9. $S9 is not running" | mail -s "$S9 down" $mail
fi
# ax25ipd
if P10=$(pgrep $S10)
then
    echo "10. $S10 is up and running, PID is $P10 - Uptime" `ps -o etime= -p "$P10"` "<br/>" >> /var/www/up/up.htm
else
    echo "10. $S10 is not running" | mail -s "$S10 down" $mail
fi
# ax25udp
if P11=$(pgrep $S11)
then
    echo "11. $S11 is up and running, PID is $P11 - Uptime" `ps -o etime= -p "$P11"` "<br/>" >> /var/www/up/up.htm
else
    echo "11. $S11 is not running" | mail -s "$S11 down" $mail
fi
# rstatrxd
if P12=$(pgrep $S12)
then
    echo "12. $S12 is up and running, PID is $P12 - Uptime" `ps -o etime= -p "$P12"` "<br/>" >> /var/www/up/up.htm
else
    echo "12. $S12 is not running" | mail -s "$S12 down" $mail
fi
# slattach
if P13=$(pgrep $S13)
then
    echo "13. $S13 is up and running, PID is $P13 - Uptime" `ps -o etime= -p "$P13"` "<br/>" >> /var/www/up/up.htm
else
    echo "13. $S13 is not running" | mail -s "$S13 down" $mail
fi
# socat
if P14=$(pgrep $S14)
then
    echo "14. $S14 is up and running, PID is $P14 <br/>" >> /var/www/up/up.htm
else
    echo "14. $S14 is not running" | mail -s "$S14 down" $mail
fi
# kissnetd
if P15=$(pgrep $S15)
then
    echo "15. $S15 is up and running, PID is $P15 <br/>" >> /var/www/up/up.htm
else
    echo "15. $S15 is not running" | mail -s "$S15 down" $mail
fi
# kissattach
if P16=$(pgrep $S16)
then
    echo "16. $S16 is up and running, PID is $P16 <br/>" >> /var/www/up/up.htm
else
    echo "16. $S16 is not running" | mail -s "$S16 down" $mail
fi
# apache2
if P17=$(pgrep $S17)
then
    echo "17. $S17 is up and running, PID is $P17 <br/>" >> /var/www/up/up.htm
else
    echo "17. $S17 is not running" | mail -s "$S17 down" $mail
fi

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.