- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Need to alert
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
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
02-25-2012 09:51 AM
02-25-2012 09:51 AM
Need to alert
Hi All,
Have the following piece of script which I need to modify so that if the count of down instances is more than 1 then it should alert otherwise should not send an email.
PROD) export ENVIRONMENT=prod INSTANCES=`some-command | awk -F: '{print $2}'` PORT=`some-command | awk -F: '{print $3}'|head -1` count_errs=0 for i in $INSTANCES do echo "" >> /tmp/var.tmp curl --connect-timeout 2 -s --retry 1 --retry-delay 20 --max-time 5 "http://$i:$PORT/dest" |sed 's/<[^>]*>//'g | egrep -A1 "DOWN|DISABLE" >> /tmp/var.tmp status=$? if [ $status -eq 0 ]; then (( count_errs += 1 )) fi done egrep -B1 -A1 "DOWN|DISABLE" /tmp/var.tmp > /tmp/var.1.tmp if [ $count_errs -ne 0 ]; then (echo "Subject:$1:Instances down"; echo "To:${EMAIL}"; echo ""; cat /tmp/var.1.tmp; ) | /usr/sbin/sendmail -t rm -f /tmp/var.tmp /tmp/dirmon_var.1.tmp fi ;;
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2012 10:19 AM
02-25-2012 10:19 AM
Re: Need to alert
>if the count of down instances is more than 1 then it should alert otherwise should not send an email.
I assume you just change: if [ $count_errs -ne 0 ]; then
To: if [ $count_errs -gt 1 ]; then
Any reason you're using sendmail directly instead of mailx?
mailx -s "$1:Instances down" ${EMAIL} < /tmp/var.1.tmp
Hmm, is $count_errors the number of instances down or is $1?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2012 10:39 AM - edited 03-09-2012 10:41 AM
03-09-2012 10:39 AM - edited 03-09-2012 10:41 AM
Re: Need to alert
It looks to me like you want to change
this text from
if [ $count_errs -ne 0 ]
to
if [ $count_errs -gt 1 ]
Run the man page on "test".
I would also change that egrep to grep -E.
I haven't used curl.
you can always look for the syntax of the the "test" command. This
if [ condition ] ; then
is the same as
if test condition ; then
tests for integer fields:
-eq, equal
-ne,notequal
-lt, lessthan
-le, less than or equal
-ge, greater than or equal
-gt, greater than
So changing "-ne 0" to " -gt 1" is the same aschanging "not equal to 0" to "greater than 1".
logic stuff:
! = not
-a = and
-o = or
string tests?
-z string test if string is 0 length. in other words it is empty.
-n string the opposite. If the string has something in it. Even a space counts.
string1!=string2 to test if the strings are different.
string1=string2 to test if the strings are the same.
Note NO spaces on either side of the equal sign. This tests if string1 is the same as string2. But what if there ARE spaces around that equal sign? Well? Then you are assigning string1 to variable string1. And because the assignment was successful, it will alway be true. (ahem as in TRUEly messed up).
Perhaps I am insulting your intelligence with this stuff. Sorry about that. I am probably rambling on too much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2012 11:43 AM
03-09-2012 11:43 AM
Re: Need to alert
>you can always look for the syntax of the the "test" command.
Unless you are using [[ ... ]].
Note that test(1) is an illusion, unless you are using the scummy C shell. ;-)
>string1!=string2 to test if the strings are different.
>string1=string2 to test if the strings are the same.
>Note NO spaces on either side of the equal sign.
No, whitespace is required! Otherwise string1=string2 is one long string, which is always true.
if [ abc=def ]; then echo T; else echo F; fi
Prints "T".
>But what if there ARE spaces around that equal sign? Then you are assigning string1 to variable string1.
Not hardly, not for a real shell.