- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Tail alternative
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
12-17-2003 03:00 AM
12-17-2003 03:00 AM
I am trying to change the monitoring ksh script into perl script. Can this be converted in perl script? Also Is it possible to mix perl script and shell script as one script?
**********
tail -f log.txt | while read LINE
do
var= `echo $LINE | grep "Error Occured"`
echo $var
done
**************
The reason being tail -f sleeps for one second according to the UNIX man pages! Sometimes the log file may be appended with lots of lines So tail is doing it very slow. It puts things in buffer and works very slow on that. I heard perl is a best alternative!
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 03:13 AM
12-17-2003 03:13 AM
Re: Tail alternative
that shouldnt matter. Most important thing is, that it doesnt miss any data. Do you have proof, that it misses data? You can of course put perl commands into the ksh script.
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 03:29 AM
12-17-2003 03:29 AM
Re: Tail alternative
Thanks for the reply. I don't see that missing any data. My log files are dumped with enormous data. After determining the error I have to do lots of operations. So I am wondering any other thing will improve the speed!
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 03:34 AM
12-17-2003 03:34 AM
Re: Tail alternative
In this use tail is just looking at the last 10 lines once each second so increase the number of lines that it looks at until you feel that you are looking far enough back into the file to catch all errors.
**********
tail -n NN -f log.txt | while read LINE
do
var= `echo $LINE | grep "Error Occured"`
echo $var
done
**************
NN = number of lines to look at
so for 50 lines:-
**********
tail -n 50 -f log.txt | while read LINE
do
var= `echo $LINE | grep "Error Occured"`
echo $var
done
**************
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 03:38 AM
12-17-2003 03:38 AM
Re: Tail alternative
if there are so many data written into the log, your approach will miss information, plus you will have to run it each time new.
Hi Dude70,
can you make a more precise search for the grep, so you get less lines?
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 03:41 AM
12-17-2003 03:41 AM
Re: Tail alternative
An option is the grep out all errors and store them in an error log and then use the tail routine on that.
Collect so:-
**********
cat log.txt | while read LINE
do
echo $LINE | grep "Error Occured" > errorlog.txt
done
**************
View so:-
then either cat or tail -n NN errorlog.txt
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 03:55 AM
12-17-2003 03:55 AM
Re: Tail alternative
I'm not sure that tail if the problem ... It goes in the 1s loop ONLY if there is not data available, so in case of many lines comming suddenly they will be immediatly displayed. But perhaps it's the application which bufferize its output ? Sometimes a fflush() in a C program can improve ...
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 03:55 AM
12-17-2003 03:55 AM
Re: Tail alternative
I have lots of data apart from "Error Occured" string written to the log. I have to look for this particular string. If this happens then I have to add following 5 lines which describes the error data and process them. Paula's approach will be good if I have only one line/one file. In contrast I have zillon files and too much of data! I was wondering whether perl will do a better job. Now I am also working for C and java alternatives!
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 04:00 AM
12-17-2003 04:00 AM
Re: Tail alternative
try this:
tail -f log.txt | while read LINE
do
if test `echo $LINE | grep "Error Occured" | wc -l` -gt 0
then
echo ${LINE}
read LINE
echo ${LINE}
read LINE
echo ${LINE}
read LINE
echo ${LINE}
read LINE
echo ${LINE}
read LINE
echo ${LINE}
done
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 04:01 AM
12-17-2003 04:01 AM
Re: Tail alternative
forgot the fi before the done!
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 04:08 AM
12-17-2003 04:08 AM
Re: Tail alternative
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 04:11 AM
12-17-2003 04:11 AM
Re: Tail alternative
Have a t look at swatch:-
http://ciac.llnl.gov/ciac/ToolsUnixSysMon.html#Swatch
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 04:27 AM
12-17-2003 04:27 AM
Re: Tail alternative
I'll post the results after testign these!
Cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 04:36 AM
12-17-2003 04:36 AM
Re: Tail alternative
Can you explain what exactly your code does?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 08:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 07:16 PM
12-17-2003 07:16 PM
Re: Tail alternative
My contribution is in 2 parts.
The tail -f part I think you know already.
The awk script does nothing until it finds the string "Error Occured" (BTW - is this spelled correctly).
Then the solitary "print" prints the current line.
Then the for loop reads in 4 more lines and prints them.
Then it waits for another occurence of the string.
The general format of an awk script is a collection of
pattern { action }
statements, so in this case pattern is "Error Occured" and action is everything between the outside braces.
Hope this helps.
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 07:51 PM
12-17-2003 07:51 PM
Re: Tail alternative
The alternative is for your script to open syslog and read from it, If there is nothing to read, it will hang until there is somethign else to read. This sounds great but will kill the performance of the machine.
Try this to see what I mean.
#!/usr/bin/perl
open SYSLOG,"
while (1){
$i=
if($i=~/Error Occured/){
print "Oh dear, we got another error $i";
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2003 08:49 AM
12-19-2003 08:49 AM
Re: Tail alternative
It works better now.