开发者

Insert rsh and module load in perl script

I am writing a perl s开发者_开发百科cript to start vnc session.

Firsr I need to rsh to a server then load a module, next execute the "vncserver -otp".

my $mod=`module load turbovnc-1.0.0; vncserver -otp 2> tmp_vnc.log`;

my $launch=`rsh $host /"$mod/"`;

print $launch;

But it does not work, any suggestions??

Thanks!!


Did you mean to use backticks in your first line?

my $mod=`module load turbovnc-1.0.0; vncserver -otp 2> tmp_vnc.log`;

This sets $mod to be the output of this sequence of commands, like running

(module load turbovnc-1.0.0; vncserver -otp 2> tmp_vnc.log) | rsh $host

from the shell. You probably wanted to say

my $mod='module load turbovnc-1.0.0; vncserver -otp 2> tmp_vnc.log';

which will set you up to run those specific commands on the remote host, and execute

rsh $host "module load turbovnc-1.0.0; vncserver -otp 2> tmp_vnc.log"


It also looks like in the rsh command that you are trying to escape the quotation marks with forward slashes. In Perl (and in everything else as far as I know), use a backslash to escape a special character.

my $launch=`rsh $host /"$mod/"`;    # / wrong /
my $launch=`rsh $host \"$mod\"`;    # \ right \
my $launch=`rsh $host "$mod"`;      # right, esc is not reqd in this case


A number of things could be going wrong, but probably the system commands are quietly failing. Either loading the module, starting the vncserver or the rsh. You can manually check for their success or failure by checking $? after each command... or you can use IPC::System::Simple and it will error out if the command fails.

I would start by doing it as a series of shell commands to make sure it works.

Then I'd rewrite the code like so using IPC::System::Simple to do the error checking. Also separating the $mod command into two commands, because I suspect you're getting back the output of running the vncserver, not loading the module.

use strict;
use warnings;

use IPC::System::Simple qw(run capture);

my $host = "something.something";

# Capture the output of loading the module
my $mod = capture('module', 'load', 'turbovnc-1.0.0');
warn "Module output: $mod\n";

# Run the VNC server
run('vncserver -otp 2> tmp_vnc.log');

# Connect to the host
my $launch = capture('ssh', $host, "/$mod/");
warn "ssh output: $launch";

There would seem to be a possibly false assumption that the location of the module on this machine is the same as the location of the module on the remote machine. That or I don't understand what you're doing with $mod.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜