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

Hello All,

I am trying to do the following in Perl using Net::SSH::Perl

ssh -f <HOSTNAME> -l <USERNAME> /usr/openwin/bin/xterm

i.e. start an xterm on a remote host sending ssh into the background.

Perl code as follows:

$cmd = "/usr/openwin/bin/xterm -display <IPADDRESS:X.Y> &";
$ssh = Net::SSH::Perl->new(<HOSTNAME>, port => 22);
$ssh->login(<USERNAME>, <PASSWORD>)
my($out, $err) = $ssh->cmd($cmd);

The problem being that the perl code is waiting for the
remote xterm to terminate. How can I background the xterm.

Any help much appreciated.

Replies are listed 'Best First'.
Re: Net::SSH::Perl and remote xterm
by Roger (Parson) on Jan 09, 2004 at 12:39 UTC
    One way I can think of is to create a separate process and launch SSH in the new process.

    use strict; use warnings; $SIG{CHLD} = "IGNORE"; my $pid = fork(); die "can not fork" if !defined $pid; if ($pid == 0) { # in child process my $cmd = "/usr/openwin/bin/xterm -display <IPADDRESS:X.Y>"; my $ssh = Net::SSH::Perl->new(<HOSTNAME>, port => 22); my $ssh->login(<USERNAME>, <PASSWORD>) my($out, $err) = $ssh->cmd($cmd); exit(0); } # in parent process # carry on doing other things...
      Do you just want to open a terminal so that users can execute commands on the remote machine? If so, there is no need to send the xterm over X-Windows.

      You can probably just fork and exec this:

      "xterm -C ssh wherever"

      Note: I am not sure if the "-C" flag is what I want, anyway, "-C" means execute, and if it's not "-C" you know what I mean :)

      Also note, it might be cool to fork and exec this instead:

      "xterm -C yourScript.pl" where yourScript.pl is the script using the SSH module, that way you can automate whatever the ssh session might want to do on the remote box, for instance, popping up a second box with some sort of custom menu.