The code below is adapted from a solution to "Use Expect in a Bash script to provide a password to an SSH command", so as to pass arguments to git push
. I'm not getting any exceptions for passing the wrong uname+pwd, and conversely passing the correct ones does not actually push anything. How can this be corrected?
git_push.sh
if (( $# == 2 ))
then
:
else
echo "expecting 'username pass', got $@"
exit 1
fi
user="$1"
pass="$2"
expect - <<EOF
spawn git push
expect 'User*'
send "$user\r"
expect 'Pass*'
send "$pass\r"
EOF
Terminal:
$ [path]/git_push.sh
spawn git push
Username for 'https://github.com': foo
Password for 'https://[email protected]':
Alternatively (no wildcards):
spawn git push
expect "Username for 'https://github.com': "
send "$user\r"
expect "Password for 'https://[email protected]': "
send "$pass\r"
expect
rather than uploading a ssh key? If for some reason you can't, my next option would be sshpass, not expect.expect
is for automating the execution of an interactive command. I don't think I'm getting mixed up.expect
script as you do not need to provide username/PATexpect
. But doesn't the question about the workings ofexpect
retain some validity?