han_perl has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to issue commands to the background with the telnet module??

This is what I'm using:
$dd_connection = Net::Telnet -> new ( Timeout=>300, Prompt => '/#/');
$dd_connection -> open( hostname );
$dd_connection -> login ( root, password);

$command = "...Some command that takes a long time &";
$dd_connection -> cmd( "$command" );
It seem that if you issue the command to the background the telnet connection stops. Then the command terminates by itself.
Is it not possible?

If not is there something else I can use?

Thanks.
  • Comment on Issuing commands to the background with telnet

Replies are listed 'Best First'.
Re: Issuing commands to the background with telnet
by tachyon (Chancellor) on Jun 10, 2004 at 03:03 UTC

    FWIW root and telnet are a bad mix. You should be using SSH in this day and age.

    Anyway Telnet is a funny protocol that involves a Network Virtual Terminal, or in short there is a lot of hidden complexity. As you may have guessed I don't use Telnet for anything more serious than talking to SMTP, HTTP, or POP servers off the command line - but I have two suggestions. Fire up the command with nohup ie cmd("nohup ./some_command &") and see if that fixes the problem. If that fails there is an example in the Net::Telnet docs of how to fork a new connection so perhaps just fork a new conn and run your long running command in its own shell.

    cheers

    tachyon

Re: Issuing commands to the background with telnet
by dba (Monk) on Jun 10, 2004 at 14:22 UTC
    As tachyon mentioned, nohup should work... I have used it before.. sample...
    @lines = $t->cmd('nohup sleep 300 &'); print @lines; @lines = $t->cmd('jobs'); print @lines; $t->close;
    output:
    [1] 6962 [1] + Running nohup sleep 300 &