- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Need Looping Script Capability - Only works for on...
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-29-2001 02:17 PM
10-29-2001 02:17 PM
My Script works fine, for only one of my servers going down in any given day. But if
I have 2 or more of my servers go down in one
day, I will only get an email for the first
one.
I need some looping help. I have tried do whiles, do untils, for in. But what I really
think I need is a way to repeat the command
to search for what I want (see INFO in script).
I want to increment and I don't know how.
Or tell it to read till end of file.
Script:
# Look in syslog for any servers going down with today's date
INFO=`grep -i "Going down" va/adm/admin/testsyslog |grep "$MYDATE"`
# Check to see the last server that went down that we sent email about
LAST=`tail -1 $EMAILLOG`
if [ "$INFO" != "" ]; then
MYHOST=`echo $INFO|awk '{print $4}'`
MYTIME=`echo $INFO|awk '{print $1,$2,$3}'`
# Did you already send an email ?
if [ "$MYHOST:$MYTIME" != "$LAST" ]; then
grep $MYHOST:$MYTIME $EMAILLOG > /dev/null 2>&1
echo "$MYHOST went down on $MYTIME" | mailx -s "$MYHOST Down" $ADMIN_EMAIL
echo "$MYHOST:$MYTIME" >> $EMAILLOG
fi
fi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2001 02:29 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2001 02:33 PM
10-29-2001 02:33 PM
Re: Need Looping Script Capability - Only works for one box per day
If you use for loop from one system to get info from remote systems then you have to use remsh
For example
for MACHINE in $MACHINES;do
# Look in syslog for any servers going down with today's date
INFO=`remsh $MACHINE grep -i "Going down" va/adm/admin/testsyslog |grep "$MYDATE"`
# Check to see the last server that went down that we sent email about
LAST=`remsh $MACHINE tail -1 $EMAILLOG`
if [ "$INFO" != "" ]; then
MYHOST=`echo $INFO|awk '{print $4}'`
MYTIME=`echo $INFO|awk '{print $1,$2,$3}'`
# Did you already send an email ?
if [ "$MYHOST:$MYTIME" != "$LAST" ]; then
remsh grep $MYHOST:$MYTIME $EMAILLOG > /dev/null 2>&1
echo "$MYHOST went down on $MYTIME" | mailx -s "$MYHOST Down" $ADMIN_EMAIL
echo "$MYHOST:$MYTIME" >> $EMAILLOG
fi
fi
done
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2001 02:42 PM
10-29-2001 02:42 PM
Re: Need Looping Script Capability - Only works for one box per day
This should work. You can verify it by removing the history file.
//start
#!/usr/bin/ksh
INFO=/tmp/info$$
HIST=history
grep -i "Going down" log >> $INFO
SYSLIST=`cat $INFO |awk '{print $4}'|sort |uniq`
ADMIN_EMAIL=some_address
if [ `wc -l $INFO|awk '{print $1}'` -ne 0 ]
then
for SYS in $SYSLIST
do
MYHOST=`grep $SYS $INFO |tail -1 |awk '{print $4}'`
MYTIME=`grep $SYS $INFO |tail -1 |awk '{print $1$2$3}'`
grep $MYHOST:$MYTIME $HIST > /dev/null 2>&1
if [ $? != 0 ]
then
echo "$MYHOST went down on $MYTIME" | mailx -s "$MYHOST Down" $ADMIN_EMAIL
echo "$MYHOST:$MYTIME" >> $HIST
fi
done
fi
//END
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2001 02:47 PM
10-29-2001 02:47 PM
Re: Need Looping Script Capability - Only works for one box per day
Danger..danger..danger...
Keep one line at the end. I am sorry.
rm $INFO
otherwise you will end up filling your /tmp with temp files.
Also, you need to replace HIST,log, ADMIN_EMAIL with your values.
-Sri