- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: shell script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 06:14 AM
10-06-2005 06:14 AM
I need a script for the following situation.
Want to run nslookup xx.xx.xx.xx ( this is a virtual ip address )
if it returns
12.16.91.93
Then no problem and output should go to a file for recording
if it returns
14.16.17.22
then it should say "problem" and send the email alert to xxyy.zz@abc.com
(sendmail is already running on the box)
The message should also get recorded in the above mentioned file
check for the size of this file if size is say more than 2mb; it should delete the file and record in a new file
this script should be running after every 25 seconds.
I don't want to run this script as a cron job.
Please suggest.
Thanks
Shiv
Solved! Go to Solution.
- Tags:
- nslookup
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 06:25 AM
10-06-2005 06:25 AM
Re: shell script
Scripting part is seperate but I do not think it would be possible to schedule it without cron. Also the frequency is also very less as minimum for the cron to work is 1 minute.
Just curious to see some responses for the same.
Regards,
Devender
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 06:34 AM
10-06-2005 06:34 AM
Re: shell script
echo "script_name" | at now + 1 minute
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 06:36 AM
10-06-2005 06:36 AM
Re: shell script
I remember a similar problem for some time ago. A possible solution is to run the script from inittab. Put a sleep 25 statment at the end of the script and use the respawn option in inittab (see /etc/inittab for examples).
- Tags:
- sleep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 07:14 AM
10-06-2005 07:14 AM
Re: shell script
Good luck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 07:17 AM
10-06-2005 07:17 AM
Re: shell script
Of course this would be a loop forever program...
Good luck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 07:37 AM
10-06-2005 07:37 AM
Re: shell script
Thanks and regards,
Shiv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 07:37 AM
10-06-2005 07:37 AM
Solutiondo #start of forever loop
IPADR=`nslookup | grep Address | awk {'print $2'}`
if [ "$IPADR" = "12.16.91.93" ]
then
(printf "Everything is fine at ";date) >> /tmp/mylogfile
else
if [ "$IPADR" = "14.16.17.22" ]
then
echo problem | sendmail xxyy.zz@abc.com
(echo "PROBLEM ENCOUNTERED at ";date) >> /tmp/mylogfile
else
(echo "UNKNOWN IP RETURNED at ";date) >> /tmp/mylogfile
fi
fi
sleep 25
LOGSIZE=`ll /tmp/mylogfile | awk {'print $5'}`
if [ $LOGSIZE -ge 2000000 ]
then
cat /dev/null > /tmp/mylogfile # zero it out
fi
done # repeat forever
if I were you I would move the logfile to .old extension for future examination and then zero it out, but this is only my opinion
hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 08:08 AM
10-06-2005 08:08 AM
Re: shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 08:27 AM
10-06-2005 08:27 AM
Re: shell script
I assume you are just testing your DNS server or servers and actually fixing that would be the real solution but till then lets get on with it.
First you want a script that is going to loop every 25 seconds or so but you probably don't want it to loop for ever and ever till the end of time. That can be done with a stop file in the /tmp directory
#!ksh
while [ ! -f /tmp/mystopfile ]
do
#do some stuff
sleep 25
done
now all you have to do is touch /tmp/mystop and the loop will drop out and stop the script
next, the business end doing the nslookup and deciding based on the results what to do
I don't know what nslookup version you are using or what switches so I will leave up to you to filter down to just the IP address
IPTRACKERLOG=/tmp/iptrackerlog
If [ wc -l $IPTRACKERLOG > 1000 ]
then
echo "log restart `date` " > $IPTRACKERLOG
fi
IPADDR=`nslookup xx.xx.xx.xx | grep Address | cut c11-`
If [ $IPADDR = "12.16.91.93" ]
Then
Echo "all is well with IP $IPADDR `date`" >> $IPTRACKERLOG
#I assume anything but this response is cause for concern so
else
echo "ERROR >>> tracker found IP $IPADDR `date`" >> $IPTRACKERLOG
#you may want to put a stop file here too and have it set its own otherwise you will get a message every 25 seconds till the script stops or the problem is fixed.
echo "your ip tracker thing on the hpux server got an error" | mailx -s "your ip check script" usr@address.com
fi
legal notice: I don't guarantee any of these commands to work the way they are listed they are here for novelty purposes only and should never actually be used till you have tested and modified them to suit your needs and even then, if it all goes bad, its still not my fault.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 05:55 PM
10-06-2005 05:55 PM
Re: shell script
#!/usr/bin/ksh
stime=25
# User input
ipaddress=""
logfile=/tmp/iplookup.log
mailID="xxyy.zz@abc.com"
while [ 1 ]
do
nslookup $ipaddress | grep -qE '12.16.91.93'
if [ $? -eq 0 ]
then
echo "Lookup Success @ $(date)" >> $logfile
fi
nslookup $ipaddress | grep -qE '14.16.17.22'
if [ $? -eq 0 ]
then
echo "Lookup Failed @ $(date)" >> $logfile
echo "Lookup Problem @ $(date)" | mailx -s"Problem" ${mailID}
fi
ret=$(ls -l $logfile | awk '{ size=$5/1048576; if ( size > 2 ) { print "1"; } else { print "2";}}')
if [ $ret -eq 1 ]
then
cat $logfile >> $logfile.old
fi
sleep $stime
done
# END
exit 0
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 06:15 PM
10-17-2005 06:15 PM
Re: shell script
i got the output as :
Lookup Success @ Mon Oct 17 23:11:25 PDT 2005
Lookup Success @ Mon Oct 17 23:11:50 PDT 2005
now suppose i want to show ip address also against success and failure in the log file then how to modify this script ?
Thanks,
Shiv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 06:19 PM
10-17-2005 06:19 PM
Re: shell script
Without this, you can grep like,
grep 'Success' /tmp/iplookup.log
grep 'Failed' /tmp/iplookup.log
to get results.
If it is not your requirement then revert here.
thx.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 06:33 PM
10-17-2005 06:33 PM
Re: shell script
if [ $? -eq 0 ]
then
echo "Lookup Success for $ipaddress @ $(date)" >> $logfile
fi
nslookup $ipaddress | grep -qE '14.16.17.22'
if [ $? -eq 0 ]
then
echo "Lookup Failed for $ipaddress @ $(date)" >> $logfile
echo "Lookup Problem for $ipaddress @ $(date)" | mailx -s"Problem" ${mailID}
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 06:49 PM
10-17-2005 06:49 PM
Re: shell script
Just change script echo statements with ${ipaddress} to get your desired output with IP-Address.
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2005 01:48 AM
11-04-2005 01:48 AM
Re: shell script
I use a process to page me in the event our primary DNS server fails..
if the NS lookup fails to return xxx.xxx.xxx.xxx then I have the system send me a page via my email pager.. Works great.
#!/bin/bash
ns=`nslookup -sil www.yourwebserver.xxx |head -1 |awk '{print $2}'`
if [ "$ns" != "xxx.xxx.xxx.xxx" ]
then
echo "Lookup failed" > lookup.txt
mail -v -s "xxx.xxx.xxx.xxx failed `date +%Y%m%d:%H%M`" name@email.xxx < lookup.txt
fi