Hi I am trying the following in my bash script which logs into my machine and runs a command. Trying to solve this using expect.
The first expect statement is hit and it enters the address "10.10.0.10" but when the second expect statement is hit it exits
#!/bin/bash
expect -c '
spawn sshpass -p "password" ssh -o StrictHostKeyChecking=no user@100.10.100.100 "source .profile && add_ip"
expect "IP Address:"
send "10.10.10.10\r"
expect "Enter IP again:"
send "10.10.10.10\r"
'
Output: ./test.sh
spawn sshpass -p password ssh -o StrictHostKeyChecking=no user@100.10.100.100
source .profile && add_ip
IP Address: 10.10.10.10
Enter IP again: ====> EXITS here without entering the IP
This doesnt enter the IP again like expected. Any ideas here? I would like to do this in a single bash script.
I added a debug statement and here is the output
expect version 5.45
argv[0] = /usr/bin/expect argv[1] = -d
set argc 0
set argv0 "/usr/bin/expect"
set argv ""
executing commands from command file
spawn sshpass -p password ssh -o StrictHostKeyChecking=no user@100.10.100.100 source .profile && add_ip
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {27493}
expect: does "" (spawn_id exp4) match glob pattern "IP Address:"? no
IP Address:
expect: does "IP Address: " (spawn_id exp4) match glob pattern "IP
Address:"? yes
expect: set expect_out(0,string) "IP Address:"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "IP Address:"
send: sending "10.10.10.10\r" to { exp4 }
expect: does " " (spawn_id exp4) match glob pattern "Enter IP again:"? no
10.10.10.10
expect: does " 10.10.10.10\r\n" (spawn_id exp4) match glob pattern
"Enter IP again:"? no
Enter IP again:
expect: does " 10.10.10.10\r\nEnter IP again: " (spawn_id exp4) match
glob pattern "Enter IP again:"? yes
expect: set expect_out(0,string) "Enter IP again:"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) " 10.10.10.10\r\nEnter IP again:"
send: sending "10.10.10.10\r" to { exp4 }