#!/usr/bin/perl -w # use strict; use POSIX; use IPC::Open3; use IO qw( Select Handle ); $|++; my $host = "host"; my $login = "login"; my $pword = "password"; my $logfil = "/var/log/syslog"; my $cmd = "telnet"; my $count = 0; my ($infh,$outfh,$errfh); my $pid; my $sel = new IO::Select; open (OUTFILE, ">deneb.log"); OUTFILE->autoflush(1); eval { $pid = open3($infh,$outfh,$errfh, "$cmd $host" ) }; die $@ if $@; $sel->add($outfh,$errfh); while (my @ready = $sel->can_read){ foreach my $fh (@ready) { my $line; my $len = sysread $fh, $line, 4096; if (not defined $len) { die "Error reading from child: $!\n"; } elsif ($len == 0){ $sel->remove($fh); }else { if ($fh == $outfh){ if ($count == 0){ print "$line\n"; print $infh "$login\n"; print $infh "$pword\n"; print $infh "tail $logfil"; $count = 1; }elsif ($count == 1){ print $infh "\n"; $count = 2; }elsif ($count == 2){ print OUTFILE $line; sleep 1; $count = 3; print $infh "exit\n"; }else {exit}; }elsif ($fh == $errfh){ print "From STDERR: $errfh\n"; }else { print "Should never be here!!\n"; } } } }