- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- scripting help reqd
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
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
09-26-2012 02:51 AM
09-26-2012 02:51 AM
hi ,
Need a help in getting a formated o/p ;
*** Start of IN635N1 at Tue Sep 25 23:12:19 IST 2012
*** End of IN635N1 at Tue Sep 25 23:12:20 IST 2012 - RC = 0
*** Start of IN9701 at Tue Sep 25 23:12:24 IST 2012
*** End of IN9701 at Tue Sep 25 23:12:26 IST 2012 - RC = 0
I need to grep RC codes from the above file and it must mail me immediately
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2012 05:10 AM
09-26-2012 05:10 AM
Re: scripting help reqd
#!/bin/sh SOURCEFILE=/some/file DESTINATION=zxcv@company.example SUBJECT="Your RC report" (printf "%8s %s\n" "Job" "RC"; \
echo "------------"; \ grep -- "- RC =" <"$SOURCEFILE" \ | awk '{printf "%8s %s\n",$4,$15}') \
| mailx -s "$SUBJECT" "$DESTINATION"
You specified you want formatted output, but you did not specify the format of the result you wanted.
The above script will produce a mail that will look like this:
To: zxcv@company.example Subject: Your RC report Job RC ------------ IN635N1 0 IN9701 0
If this is not what you wanted, please specify the output format you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2012 06:12 AM
09-26-2012 06:12 AM
Re: scripting help reqd
Hi Matti ,
My o/p file attched herewith.
I want o/p as ;
It muxt mail List of job name only other than RC = 0.
For ex:
IF9591A RC= number ( other than zero )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2012 06:14 AM
09-26-2012 06:14 AM
Re: scripting help reqd
PFA o/p file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2012 06:16 AM
09-26-2012 06:16 AM
Re: scripting help reqd
Hi Matti ,
Its an online file which gets generated daily from 9pm to 9 am.
How can we grep other than RC = 0 from it and mail it immediately.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2012 10:44 AM
09-26-2012 10:44 AM
Re: scripting help required
>How can we grep other than RC = 0 from it and mail it immediately.
You could do something like:
awk '
BEGIN { start="No previous Start line" }
/Start of/ {
start = $0 # save
next
}
/End of/ {
if ($NF != 0) { # if RC != 0, print start and stop lines
print start
print $0
}
next
}' file-name > failures.log
if [ -s failures.log ]; then
mailx -s "subject" zxcv@company.example < failures.log
fi
rm -f failures.log
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2012 04:51 AM
10-03-2012 04:51 AM
Re: scripting help required
Hi Dennis ,
The o/p is fine.
But say that file gets generated form 9 pm .
I need to put this script in cron right ?
It must be run when the input file is getting generated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2012 12:49 PM
10-03-2012 12:49 PM
Re: scripting help required
>I need to put this script in cron right? It must be run when the input file is getting generated.
Yes, you could put it in a crontab. This would mean you don't have to change how the logfile is generated.
Or you could add to the current script to scan and mail it after the file is finished.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2012 02:44 AM
10-04-2012 02:44 AM
Re: scripting help required
Hi Dennis ,
One small query , what if i want to grep after this line ;
*** Start of shutcons at Fri Sep 21 21:27:43 IST 2012
and before this line whatevr comes in between.
*** End of CI0251 at Sat Sep 22 03:37:00 IST 2012 - RC = 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2012 11:32 AM - edited 10-04-2012 03:06 PM
10-04-2012 11:32 AM - edited 10-04-2012 03:06 PM
Re: scripting help required
>what if I want to grep after this line ...
Is this a separate requirement or did you want both at the same time?
If only between those two lines:
awk '
/Start of shutcons at Fri Sep 21 21:27:43 IST 2012/, \
/End of CI0251 at Sat Sep 22 03:37:00 IST 2012/ {
print
} ' file-name
If it is that simple, you could also use sed.