[Novalug] issue with expect

Jeremy Hoel jthoel@gmail.com
Tue Dec 20 21:47:33 EST 2011


Thanks for the pointers.. I'll test that in my script and see if I can
get that to work.

The reason I am doing it in bash is that I have a lot of error
checking before the script is called... trying to idiot proof it.

You're right about the sleep piece.. that's for sure.

exp_send is an alias for send right?

Anyways.. I'll give it a try and I hope to get lucky.  Thanks.



On Tue, Dec 20, 2011 at 9:25 PM, Clif Flynt <CLIF@cflynt.com> wrote:
> Hi,
>  You probably want exp_send to send the string.
>
>  I normally start an expect script with
>
> #!expect
>
> or
> #!tclsh
> package require Expect
>
> and then I'd see the args in $argv
>
> I've never run expect in a script like that - I usually write
> the whole script in Tcl or Expect.
>
> But, I'd try:
>
> expect -c $1 $2 $3 "
>  puts $argv
> "
>
>  Rather than rely on the shell to do substitutions.
>
>  When you set exp_internal to "1", do you see the passphrase
> in the "Saw, didn't match" report?  That's a huge set of data,
> but it's worth staring at.
>
>  You need another expect to mark when the command is complete.  Else,
> it just gets to the end and exits.  The expect only runs one pass, once
> it finds a match (passphrase) it moves on.
>
>  I'm pretty sure this is not what you want.  It says to look for passphrase,
> "sleep" or eof.
>
>  expect {
>   "*passphrase*" { send $3\r\n; interact }
>  sleep 1
>   eof { exit }
>  }
>
>  You probably meant:
>
>  expect {
>   "*passphrase*" { send $3\r\n; interact;
>                    sleep 1}
>   eof { exit }
>  }
>
>
>  Here's a script that works (just tested it).  Invoke as
>
> expect /etc/passwd 192.168.1.2:/tmp user usersPasswd
>
> #!/usr/bin/expect
> foreach {file dest login passwd} $argv {break}
> exp_spawn scp $file $login@$dest
>
> while {1} {
>  expect {
>    password {exp_send $passwd\n}
>    eof {exit}
>    default {puts "NO MATCH TO: $expect_out(0,string)"}
>  }
> }
>
>  Happy Hacking,
>  Clif
>
>
> On Tue, Dec 20, 2011 at 08:19:19PM +0000, Jeremy Hoel wrote:
>> I'm trying to get a bash script working. The script is called with a
>> file, an ip and a password.  So it looks like:
>> push_updates.sh new_update 192.168.10.15 password_for_user
>>
>> In the push_updates.sh I'm using expect to scp the file 'new_update'
>> to the server <ip> using public key with the password for the key
>> <password>
>>
>> The expect part I have is:
>>
>>
>> expect -c "
>> #exp_internal 1
>> spawn /usr/bin/scp -i $HOME/.ssh/update_user_key $1 update_user@$ip:~
>> sleep 0.5
>> expect {
>>   "*passphrase*" { send $3\r\n; interact }
>> sleep 1
>>   eof { exit }
>> }
>> exit
>> "
>>
>> using this I can logon and I see the banner and the prompt for the
>> passphrase for the key, but then it just closes.  I belive the problem
>> is that it's sending the password over the ssh session and not the
>> local tty to 'unlock' the key.
>>
>> I've tried send_tty and send_user and in both cases it just exits
>> right afterwards.
>>
>> turning on debug (scp -v) shows that the server is talking, looking at
>> the key and then waiting for the password.
>>
>> Any ideas?
>> _______________________________________________
>> Novalug mailing list
>> Novalug@calypso.tux.org
>> http://calypso.tux.org/mailman/listinfo/novalug
>
> --
> ... Clif Flynt ... http://www.cwflynt.com ... clif@cflynt.com ...
> .. Tcl/Tk: A Developer's Guide (3'd edition) - Morgan Kauffman ..
> .... 19'th Annual Tcl/Tk Conference:  2012, Chicago, IL  USA ....
> .............  http://www.tcl.tk/community/tcl2012/  ............
>
>
>
>
>



More information about the Novalug mailing list