- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl equivalent needed
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
тАО04-19-2011 01:29 PM
тАО04-19-2011 01:29 PM
cat /tmp/mail |grep Appname > /tmp/mail1;cat /tmp/mail >> /tmp/mail1; mail -s "mail subject here" allan@mail.com < /tmp/mail1; >/tmp/mail ; >/tmp/mail1
==================
cat /tmp/mail
***** Alert *****
Notification Type: PROBLEM
Appname: flle system
Host: localhost
Address: 127.0.0.1
State: CRITICAL
Date/Time: Tue Apr 19 13:01:03 PDT 2011
Additional Info:
(Return code of 127 is out of bounds - plugin may be missing)
Console : http://URL
***** Alert *****
Notification Type: PROBLEM
Appname: Appname1
Host: remotehost.domain.com
Address: x.x.x.x
State: CRITICAL
Date/Time: Tue Apr 19 13:27:13 PDT 2011
Additional Info:
Connection refused
Console http://URL
===========
Want to create a Perl script which does a cat on /tmp/mail and egrep for "Appname|Date" and gives an output like this:
Tue Apr 19 13:01:03 PDT 2011 : flle system
Tue Apr 19 13:27:13 PDT 2011 : Appname1
and then send this output to my email address and finally empty out the file(s).
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2011 01:32 PM
тАО04-19-2011 01:32 PM
Re: Perl equivalent needed
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2011 04:05 PM
тАО04-19-2011 04:05 PM
SolutionThis will get the fields you want. You can redirect the output to a file or you can store it in a variable. While we could write the whole set of code in Perl, I'll leave that as an exercise for you :-)
# perl -nle 'chomp;$name=$1 if m{^Appname:\s*(.+)};print "$1 $name" if m{^Date/Time:\s*(.+)}' file
Tue Apr 19 13:01:03 PDT 2011 flle system
Tue Apr 19 13:27:13 PDT 2011 Appname1
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2011 10:40 PM
тАО04-19-2011 10:40 PM
Re: Perl equivalent needed
Tue Apr 19 13:01:03 PDT 2011 : flle system
Tue Apr 19 13:27:13 PDT 2011 : Appname1
***** Alert *****
Notification Type: PROBLEM
Appname: flle system
Host: localhost
Address: 127.0.0.1
State: CRITICAL
Date/Time: Tue Apr 19 13:01:03 PDT 2011
Additional Info:
(Return code of 127 is out of bounds - plugin may be missing)
Console : http://URL
***** Alert *****
Notification Type: PROBLEM
Appname: Appname1
Host: remotehost.domain.com
Address: x.x.x.x
State: CRITICAL
Date/Time: Tue Apr 19 13:27:13 PDT 2011
Additional Info:
Connection refused
Console http://URL
It will take me time to come up with a script but I am working.
Regards,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2011 12:05 AM
тАО04-20-2011 12:05 AM
Re: Perl equivalent needed
#!/usr/bin/ksh
/path-to-perl/perl -ne 'print if /Appname/|/Date/' /tmp/mail >
/tmp/mail_problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2011 12:10 PM
тАО04-20-2011 12:10 PM
Re: Perl equivalent needed
I have made the following script -
#!/usr/bin/perl
use strict;
my ($app,$cmd);
open(FH,"<","/tmp/mail") or die "Fail- $!\n";
open(FW,">","/tmp/mail_test") or die "Fail- $!\n";
while(
chomp;
if(/Appname:(.*)/) { $app=$1; }
if (/Date\/Time:(.*)/) { printf FW "%s:%s\n",$1,$app; }
}
$cmd='mail -s "mail subject here" allan@mail.com < /tmp/mail_test 2>/tmp/error_mail';
system($cmd);
if ( $? ne 0 ) { die "Failure - while sending email. Please check file /tmp/error_mail \n"; }
close(FW);
close(FH);
Please review and let me know of any pitfall(any stale filhandle).
In addition to Date/Appname, I am struggling a bit with printing rest of the alert text after printing Date/Appname.. Can you help?
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2011 12:15 PM
тАО04-20-2011 12:15 PM
Re: Perl equivalent needed
close(FW);
close(FH);
unlink "/tmp/mail" or warn "Could not delete email: $!";; ;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2011 02:06 PM
тАО04-20-2011 02:06 PM
Re: Perl equivalent needed
======
Appname1:remotehost.domain.com:Tue Apr 19 13:27:13 PDT 2011
...
***** Alert *****
Notification Type: PROBLEM
Appname: flle system
Host: localhost
Address: 127.0.0.1
State: CRITICAL
Date/Time: Tue Apr 19 13:01:03 PDT 2011
Additional Info:
(Return code of 127 is out of bounds - plugin may be missing)
Console : http://URL
***** Alert *****
Notification Type: PROBLEM
Appname: Appname1
Host: remotehost.domain.com
Address: x.x.x.x
State: CRITICAL
Date/Time: Tue Apr 19 13:27:13 PDT 2011
Additional Info:
Connection refused
Console http://URL
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2011 02:40 PM
тАО04-20-2011 02:40 PM
Re: Perl equivalent needed
>> Additionally can we also get host as well, so the alert should look like -
======
Appname1:remotehost.domain.com:Tue Apr 19 13:27:13 PDT 2011
This is where YOU try to really understand how the appname came to be, and replicate for the host.
(Untested!) solution below:
hth,
Hein
Instead of
> if(/Appname:(.*)/) { $app=$1; }
> if (/Date\/Time:(.*)/) { printf FW "%s:%s\n",$1,$app; }
}
try (saving 4 bytes on first line :^) :
$app = $1 if /Appname:(.*)/;
$host = $1 if /^Host:(.*)/;
if (/Date\/Time:(.*)/) { printf FW "%s:%s:%s\n",$app,$host,$1; }
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2011 03:06 PM
тАО04-20-2011 03:06 PM
Re: Perl equivalent needed
Last thing I need is to append all alerts to the bottom of this list.So something like this -
Tue Apr 19 13:01:03 PDT 2011 : flle system:Host
Tue Apr 19 13:27:13 PDT 2011 : Appname1:Host
***** Alert *****
Notification Type: PROBLEM
Appname: flle system
Host: localhost
Address: 127.0.0.1
State: CRITICAL
Date/Time: Tue Apr 19 13:01:03 PDT 2011
Additional Info:
(Return code of 127 is out of bounds - plugin may be missing)
Console : http://URL
***** Alert *****
Notification Type: PROBLEM
Appname: Appname1
Host: remotehost.domain.com
Address: x.x.x.x
State: CRITICAL
Date/Time: Tue Apr 19 13:27:13 PDT 2011
Additional Info:
Connection refused
Console http://URL
Regards,
Allan.