perldesire has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I have two things to be done.

The above two has to be a separate script. 1. firmwareupdate.pl
my $prompt = '/\/\.\/->/'; my $con = new Net::Telnet(Timeout => 400, Prompt => $prompt); $con->open("192.168.1.1"); $con->login("admin", "password"); my $prompt = '/\/\.\/map1\/firmware\/->/'; my @lines = $con->cmd(String => "cd /map1/firmware", Prompt => $prompt +); my $load_firmware = "load -source //14.0.1.0/test.bin -oemhpfiletype c +sr"; @lines = $con->cmd(String => $load_firmware, Prompt => $prompt); print join "\n",@lines; @lines = $con->cmd(String => 'reset', Prompt => '/Map1 reset\./'); $con->close();
2.loadcert.pl
my $prompt = '/\/\.\/->/'; my $con = new Net::Telnet(Timeout => 400, Prompt => $prompt); $con->open("192.168.1.1"); $con->login("admin", "password"); my $prompt = '/\/\.\/map1\/firmware\/->/'; my @lines = $con->cmd(String => "cd /map1/firmware", Prompt => $prompt +); my $load_firmware = "load -source //14.0.1.0/cert.pem -oemhpfiletype c +sr"; @lines = $con->cmd(String => $load_firmware, Prompt => $prompt); print join "\n",@lines; @lines = $con->cmd(String => 'reset', Prompt => '/Map1 reset\./'); $con->close();
3. Mainexecution.pl
my $cmd = "perl firmwareupdate.pl" if ( system($cmd) == 0 ) { print "sucess\n"; } else { print "Failed\n"; } $cmd = "perl loadcert.pl" if ( system($cmd) == 0 ) { print "sucess\n"; } else { print "Failed\n"; }

When executing Mainexecution.pl always first called script alone is getting success. If i call loadcert.pl first its getting success, when executing next script its stopped with the error "Download Unsuccessful". What could be the issues? I checked the closing part of the first called script, its returning success i.e closing perfectly.

If any body has knowledge on this, kindly give your ideas.

Replies are listed 'Best First'.
Re: Net:::Telnet - two consecutive connection
by Illuminatus (Curate) on Sep 29, 2009 at 14:46 UTC
    If I understand you correctly, you can run either of the first 2 scripts separately, and they work OK. It is only when you try to run them using the third script that you get the error message. Is this correct?
    1. Your first 2 scripts will not cause system to return 'Failed' if the commands themselves fail. You print out the results of the ->cmd operation, but as long as the command is able to be executed, then Net::Telnet is happy. You should parse the output, and die if it is not what you expect
    2. As was previously mentioned, does the 'reset' in the first script make it impossible for the second script to work for some period of time?
    3. I assume the 'Download Unsuccessful' message is something that can be printed as a result of the second scripts load call. Is it possible to pass debug or verbose options to this command to give more details?

    fnord

      Yes, I just put a sleep for few seconds in between two scripts calling, now it is working perfectly.
Re: Net:::Telnet - two consecutive connection
by lothos (Novice) on Sep 29, 2009 at 15:01 UTC
    I personally have always used Expect for telnet and ssh automation.
Re: Net:::Telnet - two consecutive connection
by Anonymous Monk on Sep 29, 2009 at 14:26 UTC

    Have you considered waiting for the device to boot (after that reset) before trying to reopen the connection? Give the commands 10 retries with 30 second delays until they succeed.

    Also, why would you do a system call when you could simply call that code as a sub instead?