in reply to Re^2: ssh using expect
in thread ssh using expect

One major thing is wrong: no error checking anywhere. Take a look at the Synopsis again, all those "or die" statements are there for a purpose (change them to "or warn" if you want a softer fail).

Also, you're mixing calls to $ssh->exec() with $ssh->waitfor, which is wrong. exec reads out the data sent by the server, so by the time waitfor is called it has nothing to ... err... wait for. You should use "send" in conjunction with "waitfor". Again, RTFM


All dogma is stupid.

Replies are listed 'Best First'.
Re^4: ssh using expect
by Anonymous Monk on Jan 12, 2012 at 15:05 UTC
    Hi, I need help with the following issue where in interactive menu selection works fine manually but fails with perl ssh expect. When executing manually i get the following:
    Please enter the operation serial number. >1 NO. NE name + NE type name + 1 TB2SEE + HW_SEE + 2 UKTB2SEE + HW_SEE + 3 TB2SLEE + HW_SLEE + 4 UKTB2SLEE + HW_SLEE + ***************Input Tips************* a: To create a tracing task for an NE, enter the NE number. b: To create a tracing task for multiple NEs, enter the NE numbers and + separate every two of them with a plus sign (+). Example: 1+2. c: To create a tracing task for all NEs, enter 0. ************************************** Please enter the NE serial number. >
    but when i run it from perl i get the following:
    main::(iTrace_start_stop.pl:48): $ssh->waitfor('Please\senter\s +the\soperation\sserial\snumber.\s*', 2) or die "prompt 'operation ser +ial number' not found after 2 second"; DB<1> main::(iTrace_start_stop.pl:49): $ssh->send("1"); DB<1> main::(iTrace_start_stop.pl:50): print $ssh->peek(1); DB<1> >1 NO.NE nameNE type name ---- More (Enter to show More) ----
    My code is as follows:
    $ssh->waitfor('Please\senter\sthe\soperation\sserial\snumber.\s*', 2) + or die "prompt 'operation serial number' not found after 2 second"; $ssh->send("1"); print $ssh->peek(1); $ssh->send("2");