- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Reading from file or variable and extract in b...
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
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
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-16-2008 08:04 PM
тАО01-16-2008 08:04 PM
Reading from file or variable and extract in between information
I need help to in extraction. I have a sed command which filters particular lines I want.
This is then stored into a variable. Or if can be pumped into another file, depending on how best the script is written.
If pumped into a file, below is the output:
Severity............: INFORMATION
Summary:
Adapter at hardware path 0/4/1/0/4/0 : CISS: RAID SA controller is now
online.
Severity............: INFORMATION
Summary:
Adapter at hardware path 0/4/1/0/4/0 : CISS: RAID SA controller is now
online.
Severity............: INFORMATION
Summary:
Adapter at hardware path 0/4/1/0/4/0 : CISS: RAID SA controller is now
online.
If in a variable, it will be in one line.
Basically, what I need to do is read the file/variable and extract and trigger an opcmsg command if it matches "Severity......: Critical" and printing the relevant Summary information with it.
"Severity............: INFORMATION
Summary:
Adapter at hardware path 0/4/1/0/4/0 : CISS: RAID SA controller is now
online."
Hope you can help me.
Thanks.
Amy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2008 12:41 AM - edited тАО09-17-2011 04:39 PM
тАО01-17-2008 12:41 AM - edited тАО09-17-2011 04:39 PM
Re: Reading from file or variable and extract in between information
If you have a file with Severity, Summary and one additional line, then you can do:
TMP=/var/tmp/ae.$$
awk '
/^Severity.*Critical/ {
print $0
getline
print $0
getline
print $0
} ' file > $TMP.2
if [ -s $TMP.2 ]; then
echo opcmsg
cat $TMP.2
fi
rm -f $TMP.2
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2008 12:45 AM
тАО01-17-2008 12:45 AM
Re: Reading from file or variable and extract in between information
Please forgive my noobness, but what does this line mean?
TMP=/var/tmp/ae.$$
is it a path? or part of the awk statement? does the path depend on the path of my file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2008 01:05 AM
тАО01-17-2008 01:05 AM
Re: Reading from file or variable and extract in between information
TMP=/var/tmp/ae.$$
>is it a path?
It is a fairly unique temporary file, based on the PID, to keep the extracted info.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2008 01:25 AM
тАО01-17-2008 01:25 AM
Re: Reading from file or variable and extract in between information
I ran your script. The cat $TMP.2 output shows 3 entries of
"Severity............: INFORMATION
Summary:
Adapter at hardware path 0/4/1/0/4/0 : CISS: RAID SA controller is now
online."
How can I make it to read each entry as one opcmsg?
Seeing from the cat output, looks like it will trigger one opcmsg with 3 entries.
amy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2008 03:52 AM
тАО01-17-2008 03:52 AM
Re: Reading from file or variable and extract in between information
No clue what a "opcmsg" is. What does it take? A string or a file or what?
If you want to jam them together you can do:
$(< $TMP.2 )
- Tags:
- command substitution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2008 06:06 PM
тАО01-17-2008 06:06 PM
Re: Reading from file or variable and extract in between information
opcmsg is a command to trigger an event alert in Openview Operations for Windows (OVOW) console. OVOW is a fault and performance monitoring application.
I would like the script to read the file (till EOF), detect EACH occurance of the specified pattern ("Severity............: INFORMATION
Summary:
Adapter at hardware path 0/4/1/0/4/0 : CISS: RAID SA controller is now
online."), and trigger the opcmsg command.
hth explains more..:)
Amy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2008 06:19 PM
тАО01-17-2008 06:19 PM
Re: Reading from file or variable and extract in between information
This is useless, you didn't answer:
What does it take? A string or a file or what?
Is it?
opcmsg severity=warning a=a o=o msg_text="test" msg_grp="test"
>EACH occurance of the specified pattern ("Severity............: INFORMATION
Summary:
You originally said, "Critical" and now you said "INFORMATION", which is it?
>trigger the opcmsg command.
So you want to do more than once?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2008 06:52 PM
тАО01-17-2008 06:52 PM
Re: Reading from file or variable and extract in between information
opcmsg severity=warning a=a o=o msg_text="test" msg_grp="test"
Occurance pattern would be "Critical".
Yes, if there are a few "Critical" occurances, it should trigger a opcmsg command for each time it finds the pattern.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2008 07:36 PM
тАО01-17-2008 07:36 PM
Re: Reading from file or variable and extract in between information
awk '
/^Severity.*Critical/ {
getline # skip "Summary:"
getline
system("echo opcmsg severity=warning a=a o=o msg_text=\""
$0 "\" msg_grp=\"test\"")
} ' file
- Tags:
- system