- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to get the next x lines after a logfile messag...
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
Forums
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
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
10-31-2003 08:18 AM
10-31-2003 08:18 AM
How to get the next x lines after a logfile message?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2003 08:28 AM
10-31-2003 08:28 AM
Re: How to get the next x lines after a logfile message?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2003 07:28 PM
11-02-2003 07:28 PM
Re: How to get the next x lines after a logfile message?
This example allows you to pass in the no of lines you want...
awk -v lines=20 '
/EXCEPTION/ {
for (i=1;i<=lines;i++) {
getline
}
}
' logfile | mail youruser
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2003 03:04 AM
11-03-2003 03:04 AM
Re: How to get the next x lines after a logfile message?
I'm having problems getting the script to run as is though... it's giving me the following:
awk: syntax error near line 1
awk: bailing out near line 1
I'm afraid I'm a bit too much of a scripting newbie to debug somethign like this... any ideas?
Thanks again!
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2003 03:08 AM
11-03-2003 03:08 AM
Re: How to get the next x lines after a logfile message?
for (i=1;i<=lines;i++) {
getline
}
should be
for (i=1;i<=lines;i++) {
getline;
print;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2003 03:11 AM
11-03-2003 03:11 AM
Re: How to get the next x lines after a logfile message?
Please check.
If still no joy please post your session output.
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2003 03:19 AM
11-03-2003 03:19 AM
Re: How to get the next x lines after a logfile message?
cpmgt2:/home/sdamon > more awk_exc
awk -v lines=20 '
/EXCEPTION/ {
for (i=1;i<=lines;i++) {
getline
}
}
' /home/sdamon/jaglogtmp | mail steve.damon@pacourts.us
cpmgt2:/home/sdamon > ./awk_exc
awk: syntax error near line 1
awk: bailing out near line 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2003 03:30 AM
11-03-2003 03:30 AM
Re: How to get the next x lines after a logfile message?
awk -v lines=20 '
/EXCEPTION/ {
should be
awk -v lines=20 '
/EXCEPTION/ {
print;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2003 03:34 AM
11-03-2003 03:34 AM
Re: How to get the next x lines after a logfile message?
your cut and paste may have introduced an invisible garbage character; apparently in the first line. If everything fails, then try and type the code in a new file by hand.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2003 03:45 AM
11-03-2003 03:45 AM
Re: How to get the next x lines after a logfile message?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2003 04:17 AM
11-03-2003 04:17 AM
Re: How to get the next x lines after a logfile message?
#!/bin/ksh
TIME=$1
NODE=$2
#echo $TIME $NODE >> /tmp/debug
#place each line with the time and the word EXCEPTION in /tmp/grepfile - precede each line with the line number
grep -n ${TIME}.*EXCEPTION mylogfile >> /tmp/grepfile
#place the first line of grepfile in the variable JUNKFILE
read JUNKLINE < /tmp/grepfile
rm /tmp/grepfile
#get just the line number and place it into /tmp/linenum
echo ${JUNKLINE} | cut -d: -f1 >> /tmp/linenum
#place the line number into the variable LINE
read LINE < /tmp/linenum
#if line number is the same as the last time the script ran, then don't send email
mv /tmp/linenum /tmp/lastline
#Place the twenty lines into a mailfile
let LINE=${LINE}+19
head -${LINE} mylogfile | tail -20 >> /tmp/mailfile
mailx -s "EXCEPTION on ${NODE}" steve.damon@pacourts.us < /tmp/mailfile
rm /tmp/mailfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2003 05:14 AM
11-03-2003 05:14 AM
Re: How to get the next x lines after a logfile message?
Hi again,
nice to hear that people are able to solve the problems themselves!
I just looked into a solaris machine and read a bit from the awk man page. Apparently, the "normal" awk on Solaris does not like the variable assignment, the -v. For the fun of it, you could try this instead:
/usr/xpg4/bin/awk -v lines=20 '
/EXCEPTION/ {
for (i=1;i<=lines;i++) {
getline
}
}
' /home/sdamon/jaglogtmp | mail steve.damon@pacourts.us
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2003 05:28 AM
11-03-2003 05:28 AM
Re: How to get the next x lines after a logfile message?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2003 07:18 PM
11-03-2003 07:18 PM
Re: How to get the next x lines after a logfile message?
Anyway, here's a slightly improved algorithm. The original would blindly print 20 lines after EXCEPTION. So if the 19th line also contained "EXCEPTION" you would get only the next (20th) line, not another 20.
This fixes that deficiency and uses other awk features for you to read up on.
And note that you do not need semicolons after commands within awk unless you are puting more that one command per line, when the semicolon is a required separator.
here you go:
/usr/xpg4/bin/awk -v lines=20 '
/EXCEPTION/ {toprint=lines+1}
(toprint-- > 0)
' /home/sdamon/jaglogtmp | mail steve.damon@pacourts.us
(And before someone points it out, this will fail if your log file has > 2147483647 lines between "EXCEPTIONS" !!)
-- Graham