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

Hy,

I am trying to write a script which will trigger a core dump on the server. The first part (triggering the dump) is complete, i am writing the second part at moment which monitors the core dump procedure.

The idea is that I log into the servers vsp and monitor it from there.

The problem: after i succesfully log into server and send a:

my ($out, $err) = $kssh->capture2("vsp");

the screen just hangs since vsp requires a esc( key combination to terminate.

When I try to solve the issue with a pty
my ($vsppty, vsppid)=$kssh->open2pty("vsp");
then I can write to to the $vsppty, but I cannot see any information that goes through it(stdout). I tried opening file handles:
my $tty = $vsppty->slave; $vsppty->make_slave_controlling_terminal(); my $ttyfd=$tty->fileno; close $vsppty; open STDIN, "<&$ttyfd" or die $!; open STDOUT, ">&$ttyfd" or die $!; open STDERR, ">&STDOUT" or die $!; close $tty;
but this gives me error:
Error: could not connect pty as controlling terminal!
I am not that expirienced yet, so I might be overlooking or not understanding something. Digging into the NET::Openssh module documents I was hoping that there is a possibility to use stdout_fh, and stdin_fh and read write to these handles, but open2pty doesnt support it.

Replies are listed 'Best First'.
Re: Perl HP ilo vsp
by salva (Canon) on May 29, 2012 at 20:44 UTC
    capture2 accepts an stdin_data options where you can pass the escape sequence used to end the command:
    my ($out, $err) = $kssh->capture2({stdin_data => $escape_seq}, "vsp");
      Hy, I tried with piping the keystrokes, but it doesn,t help. As I figured ESC+( is \x{27}(
      my $escape_seq="\x{27}("; my ($output, $errput) = $kssh->capture2({stdin_data => $escape_seq}, " +vsp"); print "my output is:'$output'\n";
      But command just hangs, only killing the process will it terminate. even tried with ^[( same problem.
        Well, getting this kind of devices to work often involves a considerable amount of trial an error until you find the exact combination of options.

        Try requesting a tty on the remote side:

        my ($output, $errput) = $kssh->capture2({tty => 1, stdin_data => $esca +pe_seq}, "vsp");
        Or adding some carrier returns before the escape sequence.

        Maybe the device will not accept the sequence until it has send some prompt. In that case, you will like to use Expect, or just use open2 to read the data and send the escape sequence when it is done.

        Try also with a timeout and setting the kill_ssh_on_timeout flag.

Re: Perl HP ilo vsp
by bulk88 (Priest) on May 30, 2012 at 03:20 UTC
    You can put escape codes in string literals in perl. For example "\e[1;10m" is a cursor position code. Control-C is "\x03". Remoting a console program is a common task with Perl. I've written perl scripts that use pipes to a local ssh client which connects to a remote ssh server, then starts screen on the remote server and multiplexes multiple programs on the remote server, and has timeouts and creates a new console in screen, then kills the hung process in the other console after a certain time period elapses.
      Hy, timeout for some reason doesn't close the connection:
      my ($output, $errput) = $kssh->capture2({timeout => 1}, "vsp");
      hangs and waits for input. Since we are on a iLO port only 1 connection at a time is allowed. Also there is no command to kill hung processes. These are the only available comands.
      HP CLI Commands: POWER : Control server power. UID : Control Unit-ID light. NMI : Generate an NMI. VM : Virtual media commands. LANGUAGE : Command to set or get default language VSP : Invoke virtual serial port. TEXTCONS : Invoke Remote Text Console.
      going to try with stin_data.
        Try sending a Control-C AKA "\x03". I'm not sure what other keys combos kill a process in linux. I'm not sure what exactly your "shell" is, are you telneting (or encrypted telnet) into the ILO module or starting a app at a prompt that connects to the ILO module? Start Wireshark (not sure if it works on Linux), start the session to the ILO module, unencrypted, do whatever key strokes you need to do by hand, stop capturing in wireshark, review the traffic for the key sequences. If you can't do it by hand at a telnet window, you can't do it with perl.

        Hi! Did you end up getting solution to this? If so, please share the same.