Jan 07 2009

Shell script for checking a sytem alive or not

Category: Shell ScriptsBipin Balakrishnan @ 6:08 pm

It is necessary in certain cases we need to check whether the system  or server is alive and if we want some alert like email or sms to inform you that the system is down.We can do it by a simple shell script .All we need is to install a package call fping

fping  is a program like ping which uses the Internet Control Message Protocol (ICMP) echo request to determine if a target host is responding.  fping differs from ping in that you can specify any number of targets on the command  line,  or  specify a file containing the lists of targets to ping. Instead of sending to one target until it  times out or replies, fping will send out a ping packet and move on to the next target in a round-robin fashion.
installing command

sudo apt-get install fping

Script:

#!/bin/sh
status=`fping 192.168.1.22 | cut -d ' ' -f 3`
if [ $status != "alive" ]
then
echo 'system is down' //Here use your alert as you like email, sms, voice alert etc
fi

Will check the system with IP 192.168.1.22 alive or not.Put it as a cron job and schedule the time interval to automatically check system status and get the alert…:)

Tags: ,


Feb 20 2008

Shell script for ftp download

Category: Shell ScriptsBipin Balakrishnan @ 3:45 pm

It is some time necessary to automatically download a file from a ftp server daily.We can automate it by writing a shell script and putting it as a cron.A sample script is show below.When it got run it will login and download the file “1.txt” in to the current working folder from the directory “ftp” in the ftp server.

#!/bin/sh
rm 1.txt
HOST=’213.104.257.88′
PORT=’21′
USER=’bipin’
PASSWD=’bipin’
FILE=’1.txt’
ftp -n $HOST $PORT <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd ftp
bin
get $FILE
quit
END_SCRIPT
exit 0

Tags: ,