- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script help
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
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
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
01-23-2012 11:31 AM - edited 01-23-2012 12:25 PM
01-23-2012 11:31 AM - edited 01-23-2012 12:25 PM
Hi All!
Have the following piece of script , there are atleast 5 URLs that it goes through and sends 5 alerts, I need to have the script send just 1 alert instead of 5. The problem is that if some app is inaccessible from the frontend URLs then I get 5 alerts instead of 1.
PROD) export ENV1=prod1 export URL1=http://tools.zzz.com:5555/apache/ww INSTANCES=`showappinst -app FrontEndApache | awk -F: '{print $1}'` mon=`showappinst -app FrontEndApache | awk -F: '{print $2}'|head -1` for i in $INSTANCES do curl --connect-timeout 2 -s --retry 3 --retry-delay 10 --max-time 3 "http://$i:$PORT/dest" | egrep "DOWN|INACCESSIBLE" curl --connect-timeout 2 -s --retry 3 --retry-delay 10 --max-time 3 "http://$i:$PORT/dest" |egrep -A1 "DOWN|INACCESSIBLE" > /tmp/mon_prod1.tmp if [ `echo $?` -eq 0 ] then echo "<html> <head> <title>destinations list</title> </head> <body> <table cellspacing="2" bgcolor="black"> <tr bgcolor="#a0a0a0"> <table> <tr>" > /tmp/mon_${ENV1}.html echo $i >> /tmp/mon_${ENV1}.html cat /tmp/mon_prod1.tmp >> /tmp/mon_${ENV1}.html echo "</tr> </table> </body> </html>" >> /tmp/mon_${ENV1}.html (echo "Subject:$1:Instances inaccessible or down in FrontEndApache"; echo "To:alert@zzz.com"; echo "Content-Type: text/html"; echo "Content-Disposition: inline"; cat /tmp/mon_${ENV1}.html; ) | /usr/sbin/sendmail -t fi echo -n "" > /tmp/mon_prod1.tmp > /tmp/monalert_${ENV1}.html done ;;
Thanks,
Allan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2012 12:51 PM - edited 01-23-2012 08:34 PM
01-23-2012 12:51 PM - edited 01-23-2012 08:34 PM
Solution>I need to have the script send just 1 alert instead of 5.
You need to send the message after your loop.
>mon=`showappinst -app FrontEndApache | awk -F: '{print $2}'|head -1`
You can optimize this to:
mon=$(showappinst -app FrontEndApache | awk -F: '{print $2; exit}')
typeset -i count_errors=0
for ...
I'm not sure why you are doing two curl commands? Combine to one.
curl --connect-timeout 2 -s --retry 3 --retry-delay 10 --max-time 3 "http://$i:$PORT/dest" | egrep -A1 "DOWN|INACCESSIBLE" > /tmp/mon_prod1.tmp
status=$?
grep -e DOWN -e INACCESSIBLE /tmp/mon_prod1.tmp # error output for user
Nor why you use echo for $? ?
if [ $status -eq 0 ]; then
(( count_errors += 1 ))
if [ $count_errors -eq 1 ]; then # first time header
echo "<html> <head> <title>destinations list</title> </head> <body> <table cellspacing="2" bgcolor="black"> <tr bgcolor="#a0a0a0"> <table> <tr>" > /tmp/mon_${ENV1}.html
fi
echo $i >> /tmp/mon_${ENV1}.html
fi
I don't think you can redirect to two files??
echo -n "" > /tmp/mon_prod1.tmp > /tmp/monalert_${ENV1}.html
Also, "echo -n" isn't valid in a real shell.
And after the end of the loop check to send message:
if [ $count_errors -ne 0 ]; then
cat /tmp/mon_prod1.tmp >> /tmp/mon_${ENV1}.html
echo "</tr> </table> </body> </html>" >> /tmp/mon_${ENV1}.html
(echo "Subject:$1:Instances inaccessible or down in FrontEndApache"; echo "To:alert@zzz.com"; echo "Content-Type: text/html"; echo "Content-Disposition: inline"; cat /tmp/mon_${ENV1}.html; ) | /usr/sbin/sendmail -t
rm -f /tmp/mon_${ENV1}.html # cleanup
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2012 05:08 PM
01-23-2012 05:08 PM