0

i'm new with Perl :)

i'm trying to write a simple script just open a CLI environment ( by executing bash command) and then send a command to that environment (only that environment familiar with this command)

for example: my linux is running in HP server machine. if i would like to see the memory configuration so under root user i need to execute: 'hpasmcli" and then i well get the following environment :

root@xxx:/>% hpasmcli HP management CLI for Linux (v2.0) Copyright 2008 Hewlett-Packard Development Group, L.P.


NOTE: Some hpasmcli commands may not be supported on all Proliant servers.

Type 'help' to get a list of all top level commands.

hpasmcli>

and now the need to enter "show dimm":


NOTE: Some hpasmcli commands may not be supported on all Proliant servers.

Type 'help' to get a list of all top level commands.

hpasmcli> show dimm

then i will get the memory configuration in the server.

so i'm tying to write a Perl script to make this simple task. i tried to use "expect" and "open(FH,"|/sbin/hpasmcli") but i was able just to log in to the CLI environment and not to send the command "show dimm"

Thank you for your help!

1

1 Answer 1

1

You might need to flush the output buffer after every write:

open my $CMD, "| /sbin/hpasmcli"
    or die "Couldn't pipe output to hpasmcli: $!";


my $old_out = select $CMD;
$| = 1;    #perl's autoflush global variable which affects the current output file handle
select $old_out;

print {$CMD} "show dimm";
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. i tried it but i got the same result as i used open(FH,...") it just log in to the CLI environment but not send the second command.
Try something simpler first: see if you can pipe some output to the cat command.
probably, you need to add the end of line marker \n to the command: print {$CMD} "show dimm\n";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.