# Establish the two telnet sessions $t1 & $t2 with a one-second # timeout to allow reasonably quick interaction with them. $t1 = new Net::Telnet (Timeout => 1, Errmode => 'return'); $t1->open($host); $t1->login($Username, $Password); $t2 = new Net::Telnet (Timeout => 1, Errmode => 'return'); $t2->open($host); $t2->login($Username, $Password); # Now start a long-running task in session 1 and a tail -f in session 2 $t1->print("touch foo_log; long_running_job arg1 arg2 arg3 >>foo_log &"); $t2->print("tail -f foo_log"); # Now print the tail -f session, and monitor the long-running task # for the "JOB COMPLETE" message while (1) { my @tail = $t2->getlines; print join("\n", @tail), "\n"; my @jobCpl = $t1->getlines; last if grep m/^JOB COMPLETE/ $t1->getlines; last if $t1->eof; } $t1->close; $t2->close;