1829115 Members
14886 Online
109986 Solutions
New Discussion

shell script

 
SOLVED
Go to solution
Shivkumar
Super Advisor

shell script

Dear Sirs;

I need to know a shell script which does a nslookup on the names abc.xx.com and xyz.ab.com every 10 minutes and records the output in a file.

Please suggest the script.

Thanks,
Shiv
4 REPLIES 4
Muthukumar_5
Honored Contributor
Solution

Re: shell script

#!/bin/ksh
# User input
LOGFILE=/tmp/nslookup.log
host1=abc.xx.com
host2=xyz.ab.com
stime=600

while [ 1 ]
do
nslookup -q $host1>> $LOGFILE
nslookup -q $host2 >> $LOGFILE
sleep $stime
done

exit 0
# END #

It will update in to /tmp/nslookup.log. You can change user inputs.

# Running script
# chmod u+x script.ksh
# ./script.ksh &
# tail -f /tmp/nslookup.log

hth.
Easy to suggest when don't know about the problem!
VEL_1
Valued Contributor

Re: shell script

Hi,

Use the following script.

hosts="abc.xx.com xyz.ab.com"

i=1
while [ $i -eq 1 ]
do
for str in $hosts
do
nslookup $str >>output_file 2>&1
if [ $? -ne 0 ]
then
echo "There is problem while nslookup $str" >>output_file 2>&1
i=0
fi
done
sleep 10
done
Muthukumar_5
Honored Contributor

Re: shell script

You can setup cron + script also as,

#!/bin/ksh
# User input
# script.ksh
LOGFILE=/tmp/nslookup.log
ERRLOG=/tmp/nslookup.err
host1=abc.xx.com
host2=xyz.ab.com

touch $ERRLOG $LOGFILE
nslookup -q $host1>> $LOGFILE 2>>$ERRLOG
nslookup -q $host2 >> $LOGFILE 2>>$ERRLOG

exit 0
# END #

# Crontab Setting
0,10,20,30,40,50 * * * * /tmp/script.ksh 1>/dev/null 2>&1

hth.
Easy to suggest when don't know about the problem!
Yogeeraj_1
Honored Contributor

Re: shell script

hi,

you can also have a look at Openview products for some advance monitoring and notification features... however, you will have to pay for this.

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)