I automatically interact with an SSH session and an ERP program using Expect.
Instead of relying on a regular expression to capture a variable in my expectation of a script, would it be possible after receiving a certain keystroke from a user to capture an area of the screen, say a single field, into a variable in the code? Send the server to other commands and resubmit this field?
Say that the order number is contained in 6, 12, 6, 18 (where 6 is the row and 12-18 are the columns) containing my 6-digit serial number. I want this order number from the columns of the 6th row from 12 to 18 to copy this value into a variable. Then allow the user to interact more (or expect to switch to another menu), and then resend the order number in another menu.
So, I think, my question is: current screen contents in one buffer? (not the whole session) Can you extract only a specific data item that will exist only in this range of rows and columns on the screen?
Pseudo-code example:
set env(TERM) vt100
spawn ssh -Y user@domain
set timeout -1
interact {
-reset $CTRLZ {exec kill -STOP [pid]}
$CTRLA {
exp_send "menu_address\ry\r"
}
$CTRLO {
exp_send "menu_exit_sequence\r"
exp_send "menu_address\r"
exp_send $ordernumvar
}
~~
}
source
share