Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Telnet module

Reply
Thread Tools

Telnet module

 
 
Indigo5
Guest
Posts: n/a
 
      05-20-2004
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");


 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      05-21-2004

Quoth "Indigo5" <(E-Mail Removed)>:
> 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/' # http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Robert Snabel-Bulka
Guest
Posts: n/a
 
      05-26-2004
"Indigo5" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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;

}
 
Reply With Quote
 
Robert Snabel-Bulka
Guest
Posts: n/a
 
      05-26-2004
"Indigo5" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Telnet - attempting to initiate a telnet session within an established telnet session Carcarius Ruby 0 12-06-2007 03:26 AM
Re: module docstring, documentation,anything? please note is the module type/object NOT some module Maric Michaud Python 0 06-24-2006 12:42 PM
Need to talk to a telnet server and send a telnet break Jim Isaacson C Programming 5 11-05-2004 09:17 PM
telnetting without a telnet module Howard Perl 2 11-17-2003 07:01 PM
How can I telnet when I dont have specific access to a telnet client Jack B. Pollack Computer Support 4 07-24-2003 08:58 PM



Advertisments