The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
tail -f wannalearn Shell Programming and Scripting 4 04-10-2007 05:22 PM
tail command.. amon Shell Programming and Scripting 2 06-02-2006 04:36 AM
Help on scripting using tail jisc Shell Programming and Scripting 4 05-19-2006 03:15 AM
how to sed with tail redlotus72 UNIX for Dummies Questions & Answers 1 08-30-2005 05:27 AM
using tail -f cdunavent Shell Programming and Scripting 6 10-23-2002 05:10 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-15-2006
qfwfq qfwfq is offline
Registered User
  
 

Join Date: Feb 2005
Location: Canada
Posts: 133
Tail??

Hello all,

I have search the forum and could not find an answer...Here is what I am trying to do. Every 15 minutes, a script send uptime output to a logfile (dailylog.log), that file contains lines like the one below:

Code:
11:21am  up 44 days, 19:15,  1 user,  load average: 0.00, 0.02, 0.03
Now, I am trying to extract only the before last line and send it to another file. The thing is that using tail -2 will show me the last 2 lines... I don't need that last line. The log is growing every 15 minutes so I don't know how many entries there are in the file.

Code:
echo $(tail -10 /dailyload.log)
Does anyone have a suggestion?
  #2 (permalink)  
Old 06-15-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
You want the next to the last line, right? And just the one line. And add the one line another file. Then wait 15 minutes and do it again?
Code:
while true
do
     tail -2 logfile | head -1 >>  anotherfile.log
     sleep 900
done
  #3 (permalink)  
Old 06-15-2006
qfwfq qfwfq is offline
Registered User
  
 

Join Date: Feb 2005
Location: Canada
Posts: 133
Tks Jim. Now what I do is putting the 13th argument of uptime command in a variable, the load, let's say 0.06 and now adding the last 24 hours load and doing an average of the total. Here is what I am trying to do:

Code:
#!/usr/bin/ksh
I_COUNT=96
C_CHAINE=0
until ((I_COUNT < 1))
do

tail -$I_COUNT /dailyload.log | head -1 | awk '{print $13}' > $C_CHAINE

#average
((C_CHAINE=C_CHAINE+$13))
((I_COUNT=I_COUNT-1))

done

((C_CHAINE=C_CHAINE/96))
echo $C_CHAINE
But can't make it work. Any idea?
  #4 (permalink)  
Old 06-15-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
It looks like you are taking the last 96 lines from the log and finding the mean of column 13.

Code:
tail -96 logfile | \
awk 'BEGIN { total=0 } { total+=$13 } END{ printf("Avg=%f\n", total/NR) }'
if I understood what you want.
  #5 (permalink)  
Old 06-16-2006
qfwfq qfwfq is offline
Registered User
  
 

Join Date: Feb 2005
Location: Canada
Posts: 133
That is exactlly what I am looking for. How could I get the highest load from the last 96 lines then?
  #6 (permalink)  
Old 06-16-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
Code:
tail -96 logfile | \
awk 'BEGIN { max=0 } { if($13>max){max=$13} } END{ printf("Max=%f\n", max) }'
  #7 (permalink)  
Old 06-16-2006
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,190
It might however be better to count the colum from the right, rather then the left, because the time in uptime may not always contain the same numbert of fields.

Instead of $13 use $(NF-2)
Sponsored Links
Closed Thread

Bookmarks

Tags
load average, performance

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0