scp script getting timed out with expect

Hi,

I have an expect script where in i am trying to scp a folder but it is getting timed out. Any help will be appreciated. (I don't have the option for sharing keys)

expect -c 2> /dev/null " spawn scp -r -o NumberOfPasswordPrompts=1 -o StrictHostKeyChecking=no root@10.10.10.10:test_dir /usr/
expect {
             "*?assword:*" { set timeout -1; send test\r\n; exp_continue }
          }
expect eof
"

Also, how to check error code if timeout has occurred?

Hello temp_user,

Following commands may help in same.

log_file /tmp/status.log
set timeout 2

By these you can check logs in a file and set the time out too in expect .

Thanks,
R. Singh

If your sysadmin doesn't allow you to share keys, they'll be absolutely livid to discover you kludging insecure solutions to automatically login as root with expect.