Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Need Help in NET::SSH::Perl to fetch the status of remote pid

by HariTheNewMonk (Initiate)
on Dec 06, 2012 at 06:31 UTC ( #1007481=perlquestion: print w/replies, xml ) Need Help??
HariTheNewMonk has asked for the wisdom of the Perl Monks concerning the following question:

Hello enlightened monks. I am new in community and I need some help. I want to know if a particular process Id is running on remote machine.But When I use the NET::SSH::Perl I get "stdout" as 0 always, irrespective of process is running or not. Please help below is my code

#!/usr/bin/perl use Net::SSH::Perl; my $host = 'xl-blr-03.ban'; my $user = 'mcsi_user'; my $password = 'password'; #-- set up a new connection my $ssh = Net::SSH::Perl->new($host); #-- authenticate $ssh->login($user, $password); #-- execute the command my($stdout, $stderr, $exit) = $ssh->cmd("kill -0 28075 ; echo $?"); print " Output is $stdout \n";

Replies are listed 'Best First'.
Re: Need Help in NET::SSH::Perl to fetch the status of remote pid
by Khen1950fx (Canon) on Dec 06, 2012 at 08:02 UTC
    I tried it on my system. It works for me; however, I did it a little differently:
    #!/usr/bin/perl -l use strict; use warnings; use Net::SSH::Perl; my $host = 'xl-blr-03.ban'; my $user = 'mcsi_user'; my $password = 'password'; my $cmd = system("kill 0 28075; echo $?"); my $ssh = Net::SSH::Perl->new($host, debug => 1); $ssh->login($user, $password); my($stdout, $stderr, $exit) = $ssh->cmd($cmd);

      Hello Khen. The example you posted does not see if the process is working on remote machine.When you give

       system("kill 0 28075; echo $?")

      you are seeing if the process exist on local machine and the system command will not return the output. Then the $cmd you pass it to remote machine . What I wanted is to execute the " process exist or not on remote machine . Please do help me

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1007481]
Approved by bitingduck
help
Chatterbox?
[MidLifeXis]: I think I forgot "running on a farm of commodore 64, vic 20s, trs 80s, and apple ]|[e systems"
[GotToBTru]: oh I know what it is .. but it is a number only slightly useful to me and of no possible use to our customer
[MidLifeXis]: Whew - you just saved the free world. <o)
[GotToBTru]: i guess it's a placeholder, the code will only fill it in if there is nothing else to use
[GotToBTru]: but then .. if you have nothing to say, why not say nothing?
[MidLifeXis]: I have a user who has a lot of say on how some of our processes work that abhors significant blanks. Perhaps that is a part of it. A not-so-obvious "this space intentionally left blank" indicator.
[MidLifeXis]: On the back end, however, that doesn't mean that i have to use that value to indicate "undefined", no matter how much he thinks I should.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2017-01-20 19:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (176 votes). Check out past polls.