Jeff Pang wrote:
hi,lists,
I have a log file which is a symbol link to the real logfile,shown as following:
$ll mssvr.log
lrwxrwxrwx 1 cmail root 40 Jan 14 00:00 mssvr.log ->
/home/cmail/logs/mssvr.log.2006-01-14
I have to access this file in perl script with unix 'tail -f' command.Part of
the code is below:
open (TAIL,"tail -f $log|") or die "can't open pipe:$!";
while(<TAIL>)
{
do something...
}
This script is a daemon script which run permanently.There is no problem when
in the same day.But when the date changed,the symbol link file will point to
another real logfile automatically (which decided by other application
program),such as:
lrwxrwxrwx 1 cmail root 40 Jan 14 00:00 mssvr.log ->
/home/cmail/logs/mssvr.log.2006-01-15
As you see,it's '2006-01-15' now, not '2006-01-14' as before.So the 'tail -f
$log' become no use for the new symbol link file,and I can't get any input from
the new logfile in the script.
How can I adjust this problem?Thanks a lot.
Jeff
You could try File::Tail from CPAN.
http://search.cpan.org/~mgrabnar/File-Tail-0.99.3/
http://search.cpan.org/~mgrabnar/File-Tail-0.99.3/Tail.pm
I haven't used it myself so I can't tell if it will solve your problem.
If it doesn't, you'll have to roll your own. Look up the following:
perldoc -f lstat
perldoc -f readlink
perldoc -f tell
perldoc -f seek
Basically, you would have to keep track of where you are in the file and
when the date changes, open the new file.
--
Just my 0.00000002 million dollars worth,
--- Shawn
"Probability is now one. Any problems that are left are your own."
SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_
* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is available at http://perldoc.perl.org/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>