Telnet module

I

Indigo5

Is there a way to open several telnet objects simultaneously? I have a
program that takes 10 hours to run and I have to run it for 200 datasets. I
would like to use the Telnet module to do this. However, I can't figure
out how to return back to the main program after I launch the process. In
other words, I want to do some parallel processing with 36 different
machines. Can this be done? In other words something like this currently
only works as serial proceessing:

$matt1 = new Net::Telnet( Timeout => 36000,
Errmode => sub { main::defaultterm()},
Prompt => '/\$$/i'),

$matt2 = new Net::Telnet( Timeout => 36000,
Errmode => sub { main::defaultterm()},
Prompt => '/\$$/i'),

$matt1->open($nodename{1});

$matt2->open($nodename{2});


$matt1->login("$uname\n","$upw\n");

$matt2->login("$uname\n","$upw\n");


$matt1->cmd("cd \/project\//$Runs{1}\/");

$matt1->cmd("../main.pl . $Runs{1} -W");


$matt2->cmd("cd \/project\/cafbeam\/SRM_RUNS\/$Runs{2}\/");

$matt2->cmd("../main.pl . $Runs{2} -W");
 
B

Ben Morrow

Quoth "Indigo5 said:
Is there a way to open several telnet objects simultaneously? I have a
program that takes 10 hours to run and I have to run it for 200 datasets. I
would like to use the Telnet module to do this. However, I can't figure
out how to return back to the main program after I launch the process. In
other words, I want to do some parallel processing with 36 different
machines. Can this be done?

The obvious way is to fork 36 process / create 36 threads.

If you don't need to know when the jobs finish, you could simply put a &
on the end of each cmd, which will start the job in the background and
return immediately. You could also use nohup or the &! feature of zsh to
allow you to close the session immediately, if that is desirable.

Ben
 
R

Robert Snabel-Bulka

Indigo5 said:
Is there a way to open several telnet objects simultaneously? I have a
program that takes 10 hours to run and I have to run it for 200 datasets. I
would like to use the Telnet module to do this. However, I can't figure
out how to return back to the main program after I launch the process. In
other words, I want to do some parallel processing with 36 different
machines. Can this be done? In other words something like this currently
only works as serial proceessing:

$matt1 = new Net::Telnet( Timeout => 36000,
Errmode => sub { main::defaultterm()},
Prompt => '/\$$/i'),

$matt2 = new Net::Telnet( Timeout => 36000,
Errmode => sub { main::defaultterm()},
Prompt => '/\$$/i'),

$matt1->open($nodename{1});

$matt2->open($nodename{2});


$matt1->login("$uname\n","$upw\n");

$matt2->login("$uname\n","$upw\n");


$matt1->cmd("cd \/project\//$Runs{1}\/");

$matt1->cmd("../main.pl . $Runs{1} -W");


$matt2->cmd("cd \/project\/cafbeam\/SRM_RUNS\/$Runs{2}\/");

$matt2->cmd("../main.pl . $Runs{2} -W");


Best is run the cmd with: 'nohup execute_script.sh &' due the SIGHUP,
FQDN of servers is stored in: 'allservers'.

#!/usr/bin/perl -w

use Net::Telnet;

my $server_file = "allservers";
my $username = "admin16";
my $passwd = "test123";
my $prompt = '/admin16 \>/';
my $kcmd = "nohup execute_script.sh &";


open (INFILE, $server_file) || die ("Couldn`t open file: $server_file
!");
@servers = <INFILE>;
close (INFILE);

foreach $host (@servers) {
chomp($host);
&telnet_connect;
}

sub telnet_connect {

$t= new Net::Telnet (Host => $host,
Timeout => 10,
Prompt => '/admin16 \>/');

$t->open($host);
$t->waitfor('/login:/i');
$t->print($username);

$t->waitfor('/Password:/i');
$t->print($passwd);

$t->waitfor('/continue/i');
$t->print("");

$t->waitfor($prompt);

@cmd=$t->cmd("$kcmd");
print @cmd;
$t->close;

}
 
R

Robert Snabel-Bulka

Indigo5 said:
Is there a way to open several telnet objects simultaneously? I have a
program that takes 10 hours to run and I have to run it for 200 datasets. I
would like to use the Telnet module to do this. However, I can't figure
out how to return back to the main program after I launch the process. In
other words, I want to do some parallel processing with 36 different
machines. Can this be done? In other words something like this currently
only works as serial proceessing:

$matt1 = new Net::Telnet( Timeout => 36000,
Errmode => sub { main::defaultterm()},
Prompt => '/\$$/i'),

$matt2 = new Net::Telnet( Timeout => 36000,
Errmode => sub { main::defaultterm()},
Prompt => '/\$$/i'),

$matt1->open($nodename{1});

$matt2->open($nodename{2});


$matt1->login("$uname\n","$upw\n");

$matt2->login("$uname\n","$upw\n");


$matt1->cmd("cd \/project\//$Runs{1}\/");

$matt1->cmd("../main.pl . $Runs{1} -W");


$matt2->cmd("cd \/project\/cafbeam\/SRM_RUNS\/$Runs{2}\/");

$matt2->cmd("../main.pl . $Runs{2} -W");

Best way is run the command with 'nohup execute_script.sh &' due
SIGHUP on UNIX or with 'at' on Win$hit ...

#!/usr/bin/perl -w

use Net::Telnet;

my $server_file = "my_allservers";
my $username = "admin16";
my $passwd = "test123";
my $prompt = '/admin16 \>/';
my $kcmd = "nohup execute_script.sh &";
#my $kcmd = "at TIME execute_script";

open (INFILE, $server_file) || die ("Couldn`t open file: $server_file
!");
@servers = <INFILE>;
close (INFILE);

foreach $host (@servers) {
chomp($host);
&telnet_connect;
}



sub telnet_connect {

$t= new Net::Telnet (Host => $host,
Timeout => 10,
Prompt => '/admin16 \>/');

$t->open($host);
$t->waitfor('/login:/i');
$t->print($username);

$t->waitfor('/Password:/i');
$t->print($passwd);

$t->waitfor('/continue/i');
$t->print("");

$t->waitfor($prompt);

@cmd=$t->cmd("$kcmd");
print @cmd;
$t->close;

}

Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top