Telnet module

Discussion in 'Perl Misc' started by Indigo5, May 20, 2004.

  1. Indigo5

    Indigo5 Guest

    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");
     
    Indigo5, May 20, 2004
    #1
    1. Advertising

  2. Indigo5

    Ben Morrow Guest

    Quoth "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?


    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, May 21, 2004
    #2
    1. Advertising

  3. "Indigo5" <> wrote in message news:<>...
    > 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, May 26, 2004
    #3
  4. "Indigo5" <> wrote in message news:<>...
    > 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
     
    Robert Snabel-Bulka, May 26, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Howard
    Replies:
    2
    Views:
    519
    GIMME
    Nov 17, 2003
  2. Jim Isaacson
    Replies:
    5
    Views:
    606
    Default User
    Nov 5, 2004
  3. Carcarius
    Replies:
    0
    Views:
    299
    Carcarius
    Dec 6, 2007
  4. Prashant Varghese

    Net-Telnet-Cisco module

    Prashant Varghese, Sep 26, 2003, in forum: Perl Misc
    Replies:
    9
    Views:
    200
    Prashant Varghese
    Sep 30, 2003
  5. Replies:
    1
    Views:
    122
    Gregory Toomey
    Apr 8, 2004
Loading...

Share This Page