3

I am trying to implement a post-commit hook on svn which will scp some files from the svn machine to some other backup machine after each commit. I have written the script with expect as follows

spawn /usr/bin/scp -r $l_dir $r_usr@$r_host:/$r_dir

expect {
        timeout { send_user "Timeout"; exit 1 }

        eof { send_user "\nConnect failed for $r_host at \n"; exit 1 }

        -re ".*es..o.*" {
        send_user "sending yes\n"
        exp_send "yes\r"
        exp_continue
        }
        -re ".*sword.*" {
        send_user "sending password\n"
        exp_send "$r_pwd\r"
        }
}
interact

This script is called from the post-commit (bash script) with all the required variables supplied.

The issue is that the when I execute the post-commit hook as

./post-commit

then the scp is succesful. but when it is triggered from an actual commit then the login andn supplying password is successful but the files are not copied

The script with debug output shows (when runnig from the commit trigger)

sending password
send: sending "vashishth\r" to { exp3 }
interact: received eof from spawn_id exp0

Using RSA keys is not possible so I have to use the scp with password. Any help would be highly appreciated.

  • If you're saying scp can't use keys, it actually can - but I wasn't sure from your question if you thought that was possible or not. – cutrightjm Dec 24 '15 at 7:06
  • I meant that sharing the keys is not allowed for the current svn and backup machine. – user1746460 Dec 24 '15 at 10:06
3

figured out with some google such cases running the expect from cron etc does not wok with interact So I replaced the

interact 

with

expect eof
exit

and the scp is successful

  • Nice work answering your own question! +1 – glenn jackman Dec 24 '15 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.