Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Telnet module (http://www.velocityreviews.com/forums/t886528-telnet-module.html)

Indigo5 05-20-2004 10:12 PM

Telnet module
 
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");



Ben Morrow 05-21-2004 12:20 AM

Re: Telnet module
 

Quoth "Indigo5" <abc@microsoft.com>:
> 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

--
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/' # ben@morrow.me.uk

Robert Snabel-Bulka 05-26-2004 02:15 PM

Re: Telnet module
 
"Indigo5" <abc@microsoft.com> wrote in message news:<Hy19oA.CrC@news.boeing.com>...
> 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;

}

Robert Snabel-Bulka 05-26-2004 03:25 PM

Re: Telnet module
 
"Indigo5" <abc@microsoft.com> wrote in message news:<Hy19oA.CrC@news.boeing.com>...
> 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


All times are GMT. The time now is 03:49 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.