Hello All,
Hopefully I'm in the correct place for this question, being that Expect is brought to us by the Tcl/Tk programmers I believe...?
I had a question regarding Exect Scripting if someone here could help me.
I am writing a script that will be called from a Bash Script as part of a program I am writing. Depending upon some command line options the
users includes, the Bash script will call this Expect Script I am writing and will open an SSH Session, login, run some commands, then exit...
The question has to do with saving aoutput into a variable.
I have this line, below. Which saves the "expected" output that it finds from a previous "send" command into a variable called "$expectedOutput":
So basically it is searching for a line that has a "#" (which would signify a command prompt). Next it runs the "ps auxww" command,
then the very next line (beginning with "lindex") will store the output from that "send" command into the "expect_out(buffer)".
In the next "expext { }" section you will see a line that starts with "set". That line will save the output in the variable "$expectOutput".
The problem is that when I save the output into a variable it causes the output of that send command to be suppressed. This can be a bit
of a problem because, if the output is being suppressed then there is nothing being printed to the screen that I would be able to "expect"
to be printed out in order to "send" some more commands.
Does anyone know if there is a work-around for this problem?
Any thoughts or suggestions would be great...!
Thanks in Advance,
Matt
Hopefully I'm in the correct place for this question, being that Expect is brought to us by the Tcl/Tk programmers I believe...?
I had a question regarding Exect Scripting if someone here could help me.
I am writing a script that will be called from a Bash Script as part of a program I am writing. Depending upon some command line options the
users includes, the Bash script will call this Expect Script I am writing and will open an SSH Session, login, run some commands, then exit...
The question has to do with saving aoutput into a variable.
I have this line, below. Which saves the "expected" output that it finds from a previous "send" command into a variable called "$expectedOutput":
Code:
expect {
-re ".*#.*" {
send -- "ps auxww | grep -v grep | grep /path/to/script/bin/myScript\r"
### This line sends the resulting output from the previous "send" command to the expect_out(buffer)...
lindex [split $::expect_out(buffer) \n] 0 }
}
timeout { exit 3 }
default { exit 13 }
}
expect {
-re ".*#.*" {
### This line saves the data stored in the expect_out(buffer) into a variable called "$expectedOutput".
set extractedOutput $expect_out(buffer)
puts "extractedOutput = --> \"$extractedOutput\"\n"
}
timeout { exit 4 }
default { exit 14 }
}
So basically it is searching for a line that has a "#" (which would signify a command prompt). Next it runs the "ps auxww" command,
then the very next line (beginning with "lindex") will store the output from that "send" command into the "expect_out(buffer)".
In the next "expext { }" section you will see a line that starts with "set". That line will save the output in the variable "$expectOutput".
The problem is that when I save the output into a variable it causes the output of that send command to be suppressed. This can be a bit
of a problem because, if the output is being suppressed then there is nothing being printed to the screen that I would be able to "expect"
to be printed out in order to "send" some more commands.
Does anyone know if there is a work-around for this problem?
Any thoughts or suggestions would be great...!
Thanks in Advance,
Matt