Platinum Solutions Corporate Website


The answer you entered to the math problem is incorrect.
Mike McKinney Wed, 1969-12-31 20:00

Expect is a great tool, and so is the TCL language (pronounced tickle)...  (go ahead Matt and Adam, I can hear you both snickering :) )  Rick, here is another way (little shorter) to accomplish what you've outlined above:

proc doWork {host} {
    puts stdout "host is $host"
}
set fp [open <path to>/hostsFile.txt r]
while {[gets $fp line] > -1} {
    set host [string trim $line]
    if {![string match "#*" $host] &&
            [string length $host]} {
        doWork $host
    }
}
close $fp

On another note, if this is something you might run quite a bit, and you don't really need the interactive nature of expect, you could update the ssh keys for all hosts and simply call

puts stdout "response from $host:

    [exec ssh $host <path to>/remoteScript.tclsh]"

within your "doWork" proc...  (multi-line strings are not an issue.)  There is a great HOWTO listed here regarding ssh-keygen : http://www.arches.uga.edu/~pkeck/ssh/

If you want to find out if you have expect loaded (it's an extension to TCL so you might not have it with your installation) you can issue the following command within a tclsh shell

info command expect

If nothing comes back, you have to go get the extension (here: http://expect.nist.gov/

Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2.
The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.

More information about formatting options