Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi, I need to send several commands and receive the response to the REMOTE server. It is a GSM user DB. I need to improve the rate on sending commands that I'm getting.I'm using Net::SSH::Expect module. Is there any other faster way? Also I was not able to store the response . I need it to apply counters on how many CMDs sent and so on... Many thanks in advance I've already written the following code: It is composed by 3 parts :
1) option handler 2) Subroutine Connection 3) Sub routine Cmds:
1) option handler:
print "Insert option number and press ENTER:\n"; my $userinput; $userinput = <STDIN>; chomp ($userinput); print "Option choosen $userinput, press ENTER\n"; ReadMode 1; #ReadMode('noecho'); $option= ReadKey(6); $option=$userinput; if($option==1){ if($runProvisioning==1){ print "\nError!\nProvisioning already started\n"; $option = 0; sleep(3); next; } splice(@thr); # clear thread table %cmdTotal = (); # clear command counters $cmdFailed = 0; # clear fail counte +r { lock ($runProvisioning); $runProvisioning = 1; } my $semaphore = Thread::Semaphore->new($num_con); $semaphore->down($num_con); # create semaphore = 0 print "\nWait...\n"; # create threads for(my $i = 0; $i < $num_con; $i++) { push @thr, threads->new(\&Connection, $i,$semaphore); sleep(2); } # foreach (@thr) { # $_->join(); # } sleep($wait2start); print "Provisioning started...\n"; sleep (2); $semaphore->up($num_con); yield(); $startTime = [gettimeofday];
2) Subroutine Connection:
sub Connection { my ($i) = shift; # thread number my ($sem) = shift; # semaphore if ($logging==1){ # LOG on my $fileLog = "log_sess_$i.log"; my $file = open ( LOGSES , '>>',$fileLog ); } my $ssh2 = Net::SSH2->new(); $Net::SSH2::Expect::Log_Stdout = 0; if ($ssh2->connect($Host1)) { if ($ssh2->auth_password($username1,$passwd1)) { print "SSH Connection $i: established\n"; my $exp = Net::SSH2::Expect->new($ssh2); my $chan = $ssh2->channel(); my $timeout = 20; my $prompt; my $output; my $ind = 0; my $data =""; my $ppid; my @cmd = (); # command table my $numCmd; # number of commands in table my %cmdCnt = (); # command type counter my $key; # command name my $value; # counter value my $sleepTime; $sem->down(); # semaphore while ($runProvisioning==1) { $exp->expect($timeout, [ qr/</ => sub { for (my $id = 0; $id < 10 +0; $id++){ # execute command table 100 times splice(@cmd); FillCmd($id,$i,\@cmd); $numCmd = @cmd; # number of commands $ind = 0; while ($ind < $numCmd){ # send all command +s in table my ($exp, $prompt) = @_; COMMAND: $exp->send("$cmd[$ind]\n"); print logses "$prompt\n"; $cmd[$ind] =~ m/(.....):/; if (exists($cmdCnt{$1})){$cmdCnt{$1} += 1;} else {$cmdCnt{$1} = 1}; $ind = $ind + 1; } } }, qr/EXECUTE/ => sub { goto COMMAND; }, qr/NOT ACCEPTED/ => sub { goto COMMAND; } ]); + # end expect method if($runProvisioning==0) { last; } + } + # end while Provisioning 1 print "\nWait while closing connection $i ...\n"; sleep (3); { lock ($runProvisioning); $runProvisioning = 0; } $sem->up(); if ($logging==1){ close(LOGSES); } print "Thread $i: closed\n"; } + } + }
3) Sub routine Cmds:
sub FillCmd { my ($step) = shift; my ($thrd) = shift; my ($refCmd) = shift; # my $comando = sprintf("AGSUI:IMSI=260000600%03d%03d,EKI=123456789 +01234567890123456789012,KIND=325,A3A8IND=4,A4IND=2;", $thrd, $step); + # push @$refCmd, $comando; my $comando = sprintf("HGSUI:IMSI=260000600%03d%03d,MSISDN=49600% +03d%03d,PROFILE=3;", $thrd, $step, $thrd, $step); push @$refCmd, $comando; $comando = sprintf ("HGSUE:MSISDN=49600%03d%03d;", $thrd, $step, + $thrd, $step); push @$refCmd, $comando; }

In reply to Sendind severals CMDs via SSH2 by using Net::SSH2::Expect module. Any other faster way? by eandalu01

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (14)
    As of 2014-07-23 11:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (140 votes), past polls