[lug] filehandles in perl question...

Tkil tkil at scrye.com
Fri Jul 28 19:29:41 MDT 2000


you *are* making sure that you only have one program adding to that
log file at a time?  it might be easier to just transfer a file over
(maybe using scp or similar) and have a process on the target machine
to the concatenation in a controlled manner.

or configure your logging mechanism to spit to a single machine as
well as to local log.

one way to try to make your current version work would be the
following, assuming that $t is your telnet object.

    $t->cmd("PS1='DONEWITHTEXT\$'");
    $t->cmd("stty -echo");
    $t->cmd("cat >> remote_log_file.txt");
 
    open LLF, $local_log_file
      or die "couldn't open local log file \"$local_log_file\" for read: $!";
    my $old_ors = $t->output_record_separator('');
    while (<LLF>)
    {
        $t->print($_);
    }
    close LLF
      or warn "closing local log file \"$local_log_file\" after read: $!";
    $t->print("\x04");
    $t->output_record_separator($old_ors);
    $t->cmd("stty echo");

but that's totally untested.  hopefully you can see what i'm trying to
do.  the perldoc for Net::Telnet has a similar example, going the
other way (retrieving file from remote machine) that is a little
fancier about dodging shell interpretation.

if you want to transfer files, transfer files, and use a protocol
designed for this.  failing that, you might get away with rsync, which
does this sort of thing over rsh or ssh tunnels.

even better, use a logging daemon that is designed for this sort of
thing, including concurrent access, etc.

t.





More information about the LUG mailing list