Need help fix my script to get alerts when the command produce n expected output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help fix my script to get alerts when the command produce n expected output
# 1  
Old 06-10-2015
Need help fix my script to get alerts when the command produce n expected output

Hi,
Below is my script, which is used to invoke a test using curl command.
Code:
#/usr/bin/sh

MAILTO=user@xyz.com
 
URL='https://myserver.xyz.net/test/dir/test123.tws'
SOAPFILE=/tmp/soap.txt

curl -k -s -S --header 'Content-Type: text/xml;charset=UTF-8' --data @"${SOAPFILE}" "${URL}" 
 

if [ $? -eq 0 ]; 
then  mailx -s "SUCCESS " $MAILTO ; 
else mailx -s "Failure " $MAILTO; 
fi

and


expected output from the script:

Code:
1) If it is successful

<?xml xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xmlns="http://dir/text123.tws"><response>MY test is  successful</response><xxxxxxxxxxxxxxxxxxxxx>



2) other than successful

a) <?xml xxxxxxxxxxxxxxxxxxxxxxxxx:Fault xmlns:axis2ns1="http://schemas.xmlsoap.org/soap/envelope/"><faultcode>xxxxxxxxxx1:Server</faultcode><faultstring>Internal Error</faultstring><detail></detail></soapenv:Fault><xxxxxxxxxxxxxx>

b)  Virtual Host to handle xxxxxxxxxxx.tws has not been defined.</H1><Bxxxxx5E: A  Virtual Host to handle server.xyz.com has not been defined.</H3><BR><I  Server</I>

The exit code on this script is always "0".
Even if i receive any of the above 3 output. (success/error/not defined etc)

My requirement is,
I would like to receive an email notification when the command (cURL) in the script fails. (**other than success )
please provide your input, so that i can receive alerts when the command in the script give output other than success.
# 2  
Old 06-10-2015
If I - having no clue of curl - interpret your post correctly, what you call "expected output" is what curl writes to stdout after downloading it successfully from the server. So its exit code will always be 0.
You might want to analyse curl's stdout for a decision "other than success".

Last edited by RudiC; 06-10-2015 at 06:23 PM..
# 3  
Old 06-11-2015
Thanks RudiC for your response.
I am actually looking into the cURL options. Usually after every execution of my script, it produce some kind of response like i mentioned in the above post.

I'm thinking to redirect/save the output response in to a file and grep "exclude success" thing, and send an email.

But i do not think its a good idea. some times output file is not getting updated when there is failure/unsuccessful situation. In that case, it is reading the old output response.
am still researching.

This is just a new thing, which am trying to implement.
Please let me know if you guys have any ideas.

Thank you.
# 4  
Old 06-11-2015
Do you want to distinguish between individual "other than successful" cases or would just "failure" suffice? Do single keywords in a line (or other features) identify a success or a failure?
This might point you in a direction:
Code:
RESARRAY=(SUCCESS FAILURE)
curl -k -s -S --header 'Content-Type: text/xml;charset=UTF-8' --data @"${SOAPFILE}" "${URL}" | awk '/success/ {XCOD=0} /[Ff]ault/ {XCOD=1} 1; END {exit XCOD}'
mailx -s ${RESARRAY[$?]} $MAILTO

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Gawk --- produce the output in pattern space instead of END space

hi, I'm trying to calculate IP addresses and their respective calls to our apache Server. The standard format of the input is HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST... (2 Replies)
Discussion started by: busyboy
2 Replies

2. Shell Programming and Scripting

Bash script unable to disable expected output

I'm trying to understand why a script behaves different when run through a pipe. My OS: Linux myip 3.13.0-92-generic #139-Ubuntu SMP Tue Jun 28 20:42:26 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux This script (myscript.sh): #!/bin/bash echo whoami: whoami echo who: who echo who... (2 Replies)
Discussion started by: SkySmart
2 Replies

3. Infrastructure Monitoring

Autosys - cleaning alerts thru command line

Hello- I am currently researching on an autosys command that can be invoked via command line that can clean-up alerts. The reason I ask is because we have jobs that activate on a daily basis. The job polls whether it needs to run or not (via filewatcher or some database check). If the job isn't... (0 Replies)
Discussion started by: cec_can
0 Replies

4. Shell Programming and Scripting

Join two files combining multiple columns and produce mix and match output

I would like to join two files when two columns in each file matches with each other and then produce an output when taking multiple columns. Like I have file A 1234,ABCD,23,JOHN,NJ,USA 2345,ABCD,24,SAM,NY,USA 5678,GHIJ,24,TOM,NY,USA 5678,WXYZ,27,MAT,NJ,USA and file B ... (2 Replies)
Discussion started by: mady135
2 Replies

5. Shell Programming and Scripting

How to produce a executable Oracle script from bash script?

Hi here's my code ${ORACLE_HOME}/bin/sqlplus /nolog <<!EOF --step 5 create db script start set feedback off set heading off set echo off conn / as sysdba spool ${ORACLE_SID}_db_link.sql SELECT 'CREATE '||DECODE(U.NAME,'PUBLIC','public ')||'DATABASE LINK '||CHR(10)... (2 Replies)
Discussion started by: jediwannabe
2 Replies

6. Shell Programming and Scripting

Not getting expected output

Hi I have written below script to get the data in table form. #!/bin/sh echo "File Name\tType" for i in *; do echo "$i\t\c" if ; then echo "directory" elif ; then echo "symbolic link" elif ; then echo "file" else echo "unknown" fi donehowever i am getting output in different way... (3 Replies)
Discussion started by: scriptor
3 Replies

7. Red Hat

how to produce date command o/p

Hello I am trying of a solution to produce date cmnd o/p as: Feb 18 is the 049 day of the year. Any ideas how to produce this? (2 Replies)
Discussion started by: ranumala
2 Replies

8. Shell Programming and Scripting

get file content and produce command

hi buddies; ip.txt: 192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4 192.168.1.5 ... parameters.txt: portvalue username password session ... (2 Replies)
Discussion started by: gc_sw
2 Replies

9. Shell Programming and Scripting

Caller Script should produce and email from 4 different script within it

Hi I wrote a shell script , which includes one output file which is emailed back to me , when the script runs . Now i want to slip the script into 4 different shell scripts each of which taking the parameter PROD or DEV, and include all the 4 different shell scripts in a caller script. ... (3 Replies)
Discussion started by: rxg
3 Replies

10. Shell Programming and Scripting

Perl Script to produce a file

hi i got a file called essay which contain few pages with many paragraphs. now i wanna with PERL to produce another file which called Essaylist that contain a sorted list of words that appear in the file essay. the format for Essaylist: $word found $times times on page a b c.... where $word... (3 Replies)
Discussion started by: mingming88
3 Replies
Login or Register to Ask a Question