Shell script to check if the Linux host is up or not


In this script we are checkiing if the host is responsive and alive or not. Also it will send  mail.
I am going to pass a parameter for host which needs to be check.

vi host_alive.sh

#!/bin/bash
host_check=$1
count=$( ping -c 1 $host_check | grep icmp* | wc -l )
if [ $count -eq 0 ]
then
    echo "Host is not Alive! Please check.." |mailx -s "Critical: $host_check is not responsive"
else
    echo "Yes! Host is Alive!"
fi

Usage:

./host_alive.sh funebs122.lab





If you like please follow and comment