LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   expect (Tcl) question (http://www.linuxquestions.org/questions/programming-9/expect-tcl-question-543080/)

kristof_v 04-03-2007 04:40 PM

expect (Tcl) question
 
hi,

I'm playing a bit around with expect.
connecting to a ftp server goes great with the following except script:

PHP Code:

spawn ftp ftp.somewhere.com
expect 
"Name" 
send "somebody\r" 
expect "Password:" 
send "secret\r" 
interact 

now I have a wrapper script to create an ftp user.
an ftp user can be created like this: ./ftpadmin create

then it prompts this:

PHP Code:

Create new FTP user

Username

Password:
Enter it again

so I edited the expect script like this:

PHP Code:

spawn ./ftpadmin create
expect 
"Username: "
send "jos\r"
expect "Password: "
send "test\r"
expect "Enter it again: "
send "test\r" 

This seems to go well until this line: expect "Enter it again: "
This is the output will in debug mode:

PHP Code:

expect version 5.42.1
argv
[0] = expect  argv[1] = -d  argv[2] = aftp.exp
set argc 0
set argv0 
"aftp.exp"
set argv ""
executing commands from command file aftp.exp
spawn 
./ftpadmin create
parent
waiting for sync byte
parent
telling child to go ahead
parent
now unsynchronized from child
spawn
returns {29452}

expectdoes "" (spawn_id exp6match glob pattern "Username: "no

expect
does "\u001b[H\u001b[2J" (spawn_id exp6match glob pattern "Username: "no
Create 
new FTP user

expect
does "\u001b[H\u001b[2JCreate new FTP user\r\n" (spawn_id exp6match glob pattern "Username: "no


expect
does "\u001b[H\u001b[2JCreate new FTP user\r\n\r\n" (spawn_id exp6match glob pattern "Username: "no
Username
:
expectdoes "\u001b[H\u001b[2JCreate new FTP user\r\n\r\nUsername: " (spawn_id exp6match glob pattern "Username: "yes
expect
set expect_out(0,string"Username: "
expectset expect_out(spawn_id"exp6"
expectset expect_out(buffer"\u001b[H\u001b[2JCreate new FTP user\r\n\r\nUsername: "
sendsending "jos\r" to exp6 }

expectdoes "" (spawn_id exp6match glob pattern "Password: "no
jos

expect
does "jos\r\n" (spawn_id exp6match glob pattern "Password: "no
Password
:
expectdoes "jos\r\nPassword: " (spawn_id exp6match glob pattern "Password: "yes
expect
set expect_out(0,string"Password: "
expectset expect_out(spawn_id"exp6"
expectset expect_out(buffer"jos\r\nPassword: "
sendsending "test\r" to exp6 }

expectdoes "" (spawn_id exp6match glob pattern "Enter it again: "no
test

expect
does "test\r\n" (spawn_id exp6match glob pattern "Enter it again: "no
expect
timed out
send
sending "test\r" to exp6 

someone any idea???
I really need to get this working :(

grtz N`Kr1pt

kristof_v 04-04-2007 03:17 AM

problem solved :)
I threw in some sleep commands to keep the expect script from getting ahead of itself

Neer 01-24-2013 06:32 AM

Having same issue
 
Hi,
I also getting same error while trying to synk expect from a automated script .
cat u please tell me how did u resolved the problem????????




set argc 1
set argv0 "package.expect"
set argv "8_2_0_0d6d6"
executing commands from command file package.expect
spawn ./package.sh
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {118451}


All times are GMT -5. The time now is 09:21 AM.