Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Want to communicate status of the last command to Windows machine

by turn2me5 (Initiate)
on Dec 19, 2006 at 07:00 UTC ( #590615=perlquestion: print w/ replies, xml ) Need Help??
turn2me5 has asked for the wisdom of the Perl Monks concerning the following question:

Hi , I am required to execute a command from my windows machine on to a Linux machine. Currently I am using Net::Telnet package for that. <pr> Now that I want to check the status of that command on my Windows machine. Is there some way where in I can return a magic string to my windows machine on the basis of value of $? variable on Linux machine. I am attaching my code here.
$username="imail1"; $passwd="imail1"; use Net::Telnet (); $t = new Net::Telnet (Timeout => 10); $t->open("172.16.14.74"); $t->print($username); $t->print($passwd); sleep(5); open(FHH, ">output.txt"); print FHH $t->cmd("cp opwv/config/config.db ./"); $flag=1; close(FHH); open(FH,"<output.txt"); while(<FH>) { if($_ =~ "ERROR"){ $flag = 0; } } if ($flag == 0) { print "Fail"; } else { print "Pass"; } close(FH); unlink("output.txt");
Please let me know whether I can modify the same code or I need to use some totally different module than Net::Telnet..
Prompt reply would be appreciated.. :)

Comment on Want to communicate status of the last command to Windows machine
Download Code
Re: Want to communicate status of the last command to Windows machine
by vladdrak (Monk) on Dec 19, 2006 at 07:20 UTC
    The environment variable %ERRORLEVEL% typically contains the exit status of the last running process. I say typically as it's up to the executable to properly exit with an actual error code.
      Right vladdrak So the problem is that how to bring that exit status back to my Windows machine, through the code above I am just telnetting to a remote machine and executing a command der Now I want to bring back the status of the process back to the Windows machine and that is the issue....!
        This code works for me against a debian etch machine -- should be very similar to another flavor of Linux, though. (You also might consider the Net::SSH module..!):
        #!/usr/bin/perl use strict; use warnings; use Net::Telnet; my $host = "somehost"; my $username = "test"; my $password = "password"; my $t = new Net::Telnet; $t->dump_log('trace.log'); # detailed packet trace $t->open($host) or die "could not connect to $host: $!\n"; $t->print($username); $t->waitfor('/ssword[:] $/'); $t->print($password); $t->waitfor('/\$ *$/'); $t->print("cp a b"); $t->getline(); # read prompt my $stdout = $t->getline(); print "stdout $stdout\n"; $t->print("echo \$?"); $t->getline(); # read prompt my $exitcode = $t->getline(); print "exit $exitcode\n"; exit($exitcode);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://590615]
Approved by chargrill
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2014-09-17 17:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (93 votes), past polls