Taking error message from XML file, amending to script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Taking error message from XML file, amending to script
# 1  
Old 04-10-2013
Hammer & Screwdriver Taking error message from XML file, amending to script

Hello all, I have a question about creating a script that will look for messages on one of our MQ series systems, and fix them.

Currently, if we issue a command for example

Code:
Command.sh errors

it gives us:

Code:

ID:c3e2d840d4f3f3d74040404040404040cb2ef4e62f70f702 <?xml version="1.0" encoding="UTF-8"?>
<XML><DATE>04/08/2013 16:09:57.000</DATE><LOCATION>/</LOCATION><NAME>report.report1.ZIP</NAME><SERVER>archive</SERVER><SIZE>737</SIZE><USERID>user</USERID><PASSWORD>userpw</PASSWORD><TIMESTAMP>1365451799978</TIMESTAMP><GROUPNAME>agroup</GROUPNAME><SYSTEM>od</SYSTEM></XML>

Manually, we usually type:

Code:
Command.sh fix c3e2d840d4f3f3d74040404040404040cb2ef4e62f70f702

I have never done this type of scripting before. Can someonepoint me in the right direction of how I can manually script it so that I don't have to manually fix the queues each message by message, sometimes there can be hundreds and it can be quite tedious. Thanks!
# 2  
Old 04-10-2013
You could code something like:
Code:
#!/bin/bash

Command.sh errors | while read line
do
        if [[ "$line" =~ ^ID: ]]                # Check if line starts with pattern - "ID:"
        then
                id=${line#ID:}                  # Remove string - "ID:" from beginning of line
                id=${id%%<*}                    # Remove string - < followed by all chars - "<*"
                Command.sh fix "$id"            # Run fix script by passing "$id" as argument
        fi
done

This User Gave Thanks to Yoda For This Post:
# 3  
Old 04-10-2013
Thank you for pointing me in the right direction. This is KSH, not sure if it makes a difference but this is the error I am getting.

Code:
mqfix.sh[3]: syntax error at line 5 : `=~' unexpected

Heres where I was going and it is not working.

Code:
cd /jeff/mq/
var1=`Command.sh fix | awk '{print substr($0,4,48);exit}' '`
echo $var1
if [ -n $var1 ]
then
 echo "There are errors on the queue..fixing"
 for i in `Command.sh fix | awk '{print substr($0,4,48);exit}' '`
 do
 Command.sh fix $1
 done
fi

# 4  
Old 04-10-2013
In KSH try this:
Code:
#!/bin/ksh

Command.sh errors | while read line
do
        if echo "$line" | egrep -q '^ID:'
        then
                id=${line#ID:}                  # Remove string - "ID:" from beginning of line
                id=${id%%\<*}                   # Remove string - < followed by all chars - "<*"
                Command.sh fix "$id"            # Run fix script by passing "$id" as argument
        fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script error message

I have this UNIX script code with a query to export sql table in Oracle and export to csv file. The code gets the data correctly. However, when I run the script second time, I got the error message "not spooling currently" and shows the older data in csv file. When I delete the csv file and run... (5 Replies)
Discussion started by: Hope
5 Replies

2. UNIX for Beginners Questions & Answers

UNIX script error message

Greeting!! I wrote the below script to e-mail me only file names in a specific directory when a file is delayed for some time in a that directory. I am getting unexpected eof error message. I don't want any email if the folder is blank.(if the condition is not met) I am not getting the email at... (4 Replies)
Discussion started by: Hope
4 Replies

3. Shell Programming and Scripting

How to deliver an error message from script?

Hi I have a script that pick up a file on another server, and place it on a solaris server, but I came across the following error: mget HLR01_21092014? 200 Port command successful 150 Opening data channel for file transfer. HLR01_21092014: No space left on device 426 Connection closed;... (18 Replies)
Discussion started by: fretagi
18 Replies

4. Programming

[XQuery] How to Convert from JSON Message to XML Message with XQuery

Hi guys, I'm in a job of converting a restful webservice to soap. Tool for convertation uses XQuery. Now i need to convert a message like this: { "firstName": "John", "midName": null, "lastName": "Smith", "married": false, "address": { "streetAddress": "21 2nd... (5 Replies)
Discussion started by: tien86
5 Replies

5. Shell Programming and Scripting

Extract XML message from a log file using awk

Dear all I have a log file and the content like this file name: temp.log <?xml version="1.0" encoding="cp850"?> <!DOCTYPE aaabbb SYSTEM '/dtdpath'> <aaabbb> <tranDtl> <msgId>000001</msgId> </tranDtl> ..... </aaabbb> ... ... (1 Reply)
Discussion started by: on9west
1 Replies

6. Shell Programming and Scripting

Self referencing script error message

Hello again all. I have a user editable script that I'd like to have point out the user error to. Problem is I'm having troubles getting an echoed error message to give me the line. Here's what I'm trying to do. grep -n $loc /this/script.sh where '$loc' is the argument passed to the script.... (9 Replies)
Discussion started by: DC Slick
9 Replies

7. Shell Programming and Scripting

script for taking the stats from a file

i have file which contains data like this every day.i need to pull up a report for counting the 203's in that file for each subscriber id.there are around 200 subscriber id's. all ths Y's which i have written in the script are the subscriber id's.could some one give me an idea as to how do it in... (22 Replies)
Discussion started by: archana234
22 Replies

8. Shell Programming and Scripting

Need to extract XML message from log

I need help to extract a following SOAP-ENV:Header XML message from the log. XML message need to be extracted: *************************** <SOAP-ENV:Header> <ServiceGatewayHeader> <SourceApplicationId>OXL</SourceApplicationId> <Version>1.0</Version> <UserId>TEST</UserId>... (4 Replies)
Discussion started by: tjshankar
4 Replies

9. Shell Programming and Scripting

How to remove xml namespace from xml file using shell script?

I have an xml file: <AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table1> <Data1 10 </Data1> <Data2 20 </Data2> <Data3 40 </Data3> <Table1> </AutoData> and I have to remove the portion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" only. I tried using sed... (10 Replies)
Discussion started by: Gary1978
10 Replies

10. UNIX for Dummies Questions & Answers

counting words then amending to a file

i want to count the number of words in a file and then redirect this to a file echo 'total number of words=' wc -users>file THis isnt working, anyone any ideas. (1 Reply)
Discussion started by: iago
1 Replies
Login or Register to Ask a Question