Hi, I wanted to automate the scp command where i do not want to enter the password each time. So thought of using expect command. Script is executing without any issues but files are not copied to remote server. Can any one help me?
Below is my shell script..
#!/bin/ksh
TMP_FILE="/tmp/testestest"
/usr/bin/expect -d <<EOD
spawn /usr/bin/scp $TMP_FILE user2@123.123.123.123:/tmp/backup/logs/
expect "password:" { send "user1234\r" }
EOD
Output:
expect version 5.42.1
argv[0] = /usr/bin/expect argv[1] = -d
set argc 0
set argv0 "/usr/bin/expect"
set argv ""
executing commands from command file
spawn /usr/bin/scp /tmp/testestest user2@123.123.123.123:/tmp/backup/logs/
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {31719550}
expect: does "" (spawn_id exp4) match glob pattern "password:"? no
********************************************************************************
* This system was LDAP clientized on Wed Aug 3 14:49:58 CUT 2011 *
********************************************************************************
expect: does "********************************************************************************\r\n* This system was LDAP clientized on Wed Aug 3 14:49:58 CUT 2011 *\r\n********************************************************************************\r\n" (spawn_id exp4) match glob pattern "password:"? no
user2@123.123.123.123's password:
expect: does "********************************************************************************\r\n* This system was LDAP clientized on Wed Aug 3 14:49:58 CUT 2011 *\r\n********************************************************************************\r\nwsadmin@159.202.157.176's password: " (spawn_id exp4) match glob pattern "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "********************************************************************************\r\n* This system was LDAP clientized on Wed Aug 3 14:49:58 CUT 2011 *\r\n********************************************************************************\r\nwsadmin@159.202.157.176's password:"
send: sending "user1234\r" to { exp4 }