Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The numbers at the end are counts for the age, so if there are 2 males of age 34 then instead of writing male,34,1 twice. Its easier to have male,34,2.
I assume you mean you are reading the output from a ksh file, not reading the ksh prog file.
Where does the 2 mins thing come from?
Does the ksh prog produce a new file every 2 mins?
Does it output for 2 mins then overwrite the same file?
In either case, synchronisation is key to avoid losing data.
In either case (or even if this is a continuous stream being out put eg like a logfile), I would highly recommend http://search.cpan.org/~mgrabnar/Fil...0.99.3/Tail.pm which is designed to handle those situations.
I've used it myself; very handy.
Does the ksh prog produce a new file every 2 mins?
Does it output for 2 mins then overwrite the same file?
In either case, synchronisation is key to avoid losing data.
The 2 minute thing came because i want the script to loop for 2 minutes and not until the end of the file. This will help me to log messages coming every 2 minutes.
The ksh file produces new message every couple seconds and each new message overwrites the previous message.
And yes you are right i want to avoid losing data.
Quote:
In either case (or even if this is a continuous stream being out put eg like a logfile), I would highly recommend http://search.cpan.org/~mgrabnar/Fil...0.99.3/Tail.pm which is designed to handle those situations.
This link is PERL code and i am not familiar with PERL coding. I have never used PERL and also File tail wouldn't this get the end of the file. my file as soon as new message arrives it overwrite the previous message so i am not sure if this will do what i want.
@cbtshare,
I can't use cron scheduler and this why I am not sure how i could solve this issue.
The ksh file produces new message every couple seconds and each new message overwrites the previous message.
...
my file as soon as new message arrives it overwrite the previous message
Taking this to mean what it says, you are saying that the output_file (using that term loosely) only ever actually contains one msg (the latest), which is overwritten by the next/new msg approx(!) every 1 or 2 secs.
in that case, I don't get the 2 mins thing at all. You've got to grab each msg immediately or you will lose it...
So, you do need to use something like that Perl module or eg
Code:
tail -f output_file | your post-processing prog
In fact, you could use the first example on that Perl page pretty much as is.
Going back to bash soln, maybe instead of having the ksh file write to the ever-changing file, just pipe the output directly thus
Code:
ksh_prog | post-process_prog
# or output to log and pipe to prog
ksh_prog | tee ksh.log | post_process_prog
Thank you all for replying, but I think I haven’t explained myself.
I have .ksh file which contains XML messages.
What I need is to parse and capture this XML messages then store the output in log file.
The two minutes thing is something I came up with as the log file could be a large file if I get each message output to it. But if I collect the messages for 2 minutes then I will be able to get summary output as this example:
I am not sure I understand your current issue? You have been presented with code to parse the xml and retrieve data. Redirecting this into a new file should be trivial.
If you are referring to the bash code, this code does almost what my AWK code does?
I could parse and retrieve the data then redirect to output file. But the only problem with AWK is that it reads the whole file at once and what I want is to read part of the file each minute or so.
If this is not possible then parse messages then log output in file, but this should include the current time and count of the messages.
For the PERL link I am getting this error and I am not sure how this should parse XML messages.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.