'expect' issues

From: sun@bagdon.com
Date: Thu Dec 05 2002 - 07:21:02 EST


If there are any hardcore 'expect' people out there, perhaps you can
assist with this question:

I'm working on a script that will ssh to a remote host, then do a sudo.
With sudo if you were in within a certain period of time, you don't need
to put in a password again. This slice of code handles this:

        expect -exact "$"
        send -- "sudo usermod -G 99 user\r"
        set timeout 5
        expect -exact "Password:" { send -- "$password\r" }
        set timeout -1

The script will wait 5 seconds after a sudo for a password - whether it
has to wait or not. If you entered a password 5 minutes again, you end up
sitting and waiting for 5 seconds, while if the command completed in .1
seconds, you still have to wait 4.9 seconds for it to timeout. Not an
issue - unless you're doing this to 200 hosts.

So, what I'm looking for is something like this:

        expect -exact "$"
        send -- "sudo usermod -G 99 user\r"
        set timeout 60
        expect -exact "Password:" { send -- "$password\r" }
          OR -EXACT "$" # continue immediately
        set timeout -1

So it will wait 60 seconds for a password prompt (REALLY slow systems),
but if the command completes in .5 seconds it'll continue immediately. So
I'm saying 'wait 60 seconds for Password, but if $ comes up instead
continue immediately and don't wait'.

I'm looking in examples, man pages, docs, etc, but if anyone has any
experience with 'conditional expects', let me know.

Thanks!

Steve B.
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 23:25:25 EDT