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}
expect: does "" (spawn_id exp6) match glob pattern "Username: "? no
expect: does "\u001b[H\u001b[2J" (spawn_id exp6) match glob pattern "Username: "? no
Create new FTP user
expect: does "\u001b[H\u001b[2JCreate new FTP user\r\n" (spawn_id exp6) match glob pattern "Username: "? no
expect: does "\u001b[H\u001b[2JCreate new FTP user\r\n\r\n" (spawn_id exp6) match glob pattern "Username: "? no
Username:
expect: does "\u001b[H\u001b[2JCreate new FTP user\r\n\r\nUsername: " (spawn_id exp6) match glob pattern "Username: "? yes
expect: set expect_out(0,string) "Username: "
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "\u001b[H\u001b[2JCreate new FTP user\r\n\r\nUsername: "
send: sending "jos\r" to { exp6 }
expect: does "" (spawn_id exp6) match glob pattern "Password: "? no
jos
expect: does "jos\r\n" (spawn_id exp6) match glob pattern "Password: "? no
Password:
expect: does "jos\r\nPassword: " (spawn_id exp6) match glob pattern "Password: "? yes
expect: set expect_out(0,string) "Password: "
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "jos\r\nPassword: "
send: sending "test\r" to { exp6 }
expect: does "" (spawn_id exp6) match glob pattern "Enter it again: "? no
test
expect: does "test\r\n" (spawn_id exp6) match 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