Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Command execution through pipe from Open function

by msk_0984 (Friar)
on Apr 29, 2008 at 11:29 UTC ( [id://683443]=perlquestion: print w/replies, xml ) Need Help??

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

Respected Monks,

I am trying to execute few commands by using the pipe from open function and pushing the required information into files and reading the same data.

open (CONS,"| SSM/bin/ssmcons $ip > ./logs/ssm/$ip 2>&1") or +die "Could not open: $!"; print CONS "$password \n"; print CONS "subagent list\n"; print CONS "quit\n"; close (CONS);
The first command after execution opens a new command prompt , for which we provide a password for authentication and then give the required command "subagent list" to get some health information and quit the command prompt. Its gives the perfect output when the password specified to it is correct. All the information is pushed into the files.

But when we execute the same commands on the command prompt by giving an incorrect password, it retries for three times and prints a message
"Aborted Negotiation"

But when trying the same in-correct password scenario using the open pipe function. In the result file we can only see the "Incorrect password" trying for three times and not giving out the below expected message.
"Aborted Negotiation"

And inturn when checked for the process status using the ps command I could see that the incorrect password process is running continously and even its consuming more CPU usage around ( 50% ) by monitoring the CPU usage.

> ps -ef | grep ssmcons nobody 2441 2440 50 15:25:45 ? 63:00 ../../htdocs/bin/ssmcon +s.bin ip_address nobody 2440 1 0 15:25:45 ? 0:00 sh -c ../../htdocs/bin/ +ssmcons ip_address > ./logs/ssm/ip_address PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLW +P 2441 nobody 5224K 3048K cpu0 20 0 1:04:40 50% ssmcons.bin +/1
And the main concern is that in case of incorrect password scenario, the above process is running continously and also consuming excess CPU usage. Any suggestion regarding the above would be of great help.

Thanks in Advance.


Sushil Kumar

Replies are listed 'Best First'.
Re: Command execution through pipe from Open function
by casiano (Pilgrim) on Apr 29, 2008 at 12:11 UTC
    Sushil,

    You can try to use open2 or open3 instead. That will keep you in control of the output and see if the password was accepted or rejected.

    Casiano

Re: Command execution through pipe from Open function
by Fletch (Bishop) on Apr 29, 2008 at 12:50 UTC

    It's also possible that the command expects to be run from a real tty, in which case you might want to look at using the Expect module to run it on one and see if it's more well behaved.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found