I'm working on an expect script to automate remote logins and in turn, run certain commands rather than just dropping to an interactive shell.
I am new to TCL and expect, but I've found a lot of helpful stuff in the man page and online. One thing I tried googling for but didn't come up with any results on, is how to use non-expect, TCL code (if statements, etc) nested inside of an expect statement.
Something like the following code fragment is what I would like to get working, if at all possible, without having to write multiple expect statements:
Code:
# interact will be the last arg, if it exists, and should be either 1 or 0 for this fragment
set interactive [lrange $argv end end]
expect {
# expect the end of the colorized prompt (because our system
# designers are stupid and want pretty colors)
"\[\033\[01;36m\]\$ \[\033\[00m$" {
if {$interactive} {
interact
} else {
send -- "sudo bash\r"
exp_continue
}
}
}
I essentially just want to be able to have if statements used within the context of certain output from the shell that I am logging into. Any ideas?
EDIT:
After trying the above code fragment (which I didn't try quite like this), I was able to get it to work.