Skip to content

Instantly share code, notes, and snippets.

@manjeshpv
Created June 19, 2015 08:10
Show Gist options
  • Save manjeshpv/3a221e259ffa824b28f7 to your computer and use it in GitHub Desktop.
Save manjeshpv/3a221e259ffa824b28f7 to your computer and use it in GitHub Desktop.
Bash Shell Script to Ping a ip/host continuously to keep connectivity
#/bin/sh
# Description: Cyberoam Ping Script
# save in /etc/init.d/pinger
# start : $ server pinger start
# status : $ server pinger status
# stop : $ server pinger stop
# Description: Cyberoam Ping Script
address=192.168.220.250
do_start()
{
result=$(pgrep -f "ping $address")
if [ ! -z "$result" ]
then
echo "Service Already Running"
pgrep -f "ping $address"
else
echo "Starting Service"
ping ${address} > /dev/null & # /tmp/ping.$ &
pgrep -f "ping $address"
fi
}
do_stop()
{
result=$(pgrep -f "ping $address")
if [ ! -z "$result" ]
then
kill -9 $(pgrep -f "ping $address")
echo "Stopped"
pgrep -f "ping $address"
else
echo "Service not running"
pgrep -f "ping $address"
fi
}
do_status()
{
result=$(pgrep -f "ping $address")
if [ ! -z "$result" ]
then
echo "Service Running"
pgrep -f "ping $address"
else
echo "Service Not Running"
fi
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
status)
do_status
;;
esac
exit 0
#/bin/sh
# Description: Cyberoam Ping Script
address=192.168.220.250
do_start()
{
result=$(pgrep -f "ping $address")
if [ ! -z "$result" ]
then
echo "Service Already Running"
pgrep -f "ping $address"
else
echo "Starting Service"
ping ${address} > /dev/null & # /tmp/ping.$ &
pgrep -f "ping $address"
fi
}
do_stop()
{
result=$(pgrep -f "ping $address")
if [ ! -z "$result" ]
then
kill -9 $(pgrep -f "ping $address")
echo "Stopped"
pgrep -f "ping $address"
else
echo "Service not running"
pgrep -f "ping $address"
fi
}
do_status()
{
result=$(pgrep -f "ping $address")
if [ ! -z "$result" ]
then
echo "Service Running"
pgrep -f "ping $address"
else
echo "Service Not Running"
fi
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
status)
do_status
;;
esac
exit 0
address=192.168.220.250
do_start()
{
result=$(pgrep -f "ping $address")
if [ ! -z "$result" ]
then
echo "Service Already Running"
pgrep -f "ping $address"
else
echo "Starting Service"
ping ${address} > /dev/null & # /tmp/ping.$ &
pgrep -f "ping $address"
fi
}
do_stop()
{
result=$(pgrep -f "ping $address")
if [ ! -z "$result" ]
then
kill -9 $(pgrep -f "ping $address")
echo "Stopped"
pgrep -f "ping $address"
else
echo "Service not running"
pgrep -f "ping $address"
fi
}
do_status()
{
result=$(pgrep -f "ping $address")
if [ ! -z "$result" ]
then
echo "Service Running"
pgrep -f "ping $address"
else
echo "Service Not Running"
fi
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
status)
do_status
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment