[Ilugc] Shell scripting help

  • From: jujubha@xxxxxxxxx (Chandrakumar Muthaiah)
  • Date: Sun Jan 9 13:27:26 2005

This will do.
create it as ~/scripts/ping-ip.sh

-----------------------8<--------------------
#!/bin/sh

ip=$1
if [ "x$ip" == "x" ]; then
        echo "Need an IP address"
        exit 1
fi

ping -c 1 $ip < /dev/null > /dev/null 2>&1

if [ $? -eq 0 ]; then
        echo 1 > ~/ip.log
else
        echo 0 > ~/ip.log
fi
-----------------------8<--------------------

run it as

~/scripts/ping-ip.sh 192.168.1.1 </dev/null > /dev/null 2>&1

Rohit Baisakhiya wrote:

Hello Luggers
I am new to shell scripting in linux.I need to make a script which can
ping an ip and can write to a file in values of 0 or 1(0 if it
receives ping reply and 1 if it receives no reply).I want to put the
script in crontab such that it tuns every 30 seconds and writes the
value to the file.

Any kind of pointers or help is appriciated.Please help.

 


Other related posts: