How can I instruct expect to look for something like “Generating foo-[pattern].tgz” in the stream and return the pattern so I can use it in future commands?
I find myself repeatedly performing the same actions and would like to automate them using expect. I ssh onto one system and run a script on it that generates a file, then I scp the file from that system onto two other systems.
I can spawn ssh and trigger the file build successfully. I’m uncertain how to capture the name of the generated file to perform the copy. The script outputs something like “Generating foo-timestamp.tgz… Done.” and timestamp obviously varies between runs, and I don’t want to glob scp (ie scp foo-*tgz) because there might be stale foo files (hence the timestamp).
I’m new to expect and still stumbling through examples and such, and occasionally still need a bit of hand holding. Any suggestions/help are much appreciated.
I am not aware if we can capture the pattern, but what I normally do in such situations is store output in a variable and then use this output. For Example, if
send -- "./executeSomeScript\r"will give an output like “Generating foo-timestamp.tgz … Done”, i’ll replace the send command withand finally
Please note that escaping
$is necessary so that it is not interpreted at script level but send as literal to the remote shell.