0

Currently i'm writing a bash script to cd into a folder and run git pull with the password prompt

Notes: my git server is private so i'm using the following git remote url ssh://username@ip-address/path-to-git-folder so i can't use https with password within the url

I'm trying the following bash script

#!/bin/bash
cd /path-to-repo/repo-folder
echo "mygitpassword" | sudo -S git pull

which doesn't work, i checked and it doesn't pull the changes

i also tried to used expect command prompt like the following:

#!/bin/bash
cd /path-to-repo/repo-folder
/usr/bin/expect <<EOF
spawn git pull
expect -re "^.*password.*$"
send -- "mygitpassword\r"
EOF
echo "Done"

from the debug i can see that the regex matched and it's sending the "mygitpassword" (i can't copy paste the debug because i'm using a streaming machine)

summary of the expect debug output:

...
expect: does 'username@ip password: '(spawn_id exp6) match regular expression "^.*password.*$"? Gate "*password*? gate=yes re=yes
expect: set expect_out(0, string) "username@ip's password: "
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "username@ip's password: "
send: sending "mygitpassword\r" to { exp6 }
Done

both methods showing it running till the echo "Done" but none are actually inputing the password

Right now i'm out of options with git pull(i can't do ssh git pull because i don't have access to the company git private server)

11
  • add expect -timeout 60 eof after sending the password. change the timeout value as needed. Commented Apr 25, 2022 at 4:47
  • 1
    Just curious here, why not use SSH keys and not have to deal with this? Commented Apr 25, 2022 at 4:53
  • @fredrik i mentioned in the question, i cannot setup ssh key authentication because i don't have access to the git server(can't edit authorized_keys file) Commented Apr 25, 2022 at 4:55
  • @sexpect-ExpectforShells thank you! that worked now, i wonder why i need expect eof at the end? if you can post it in the answer i will accept it Commented Apr 25, 2022 at 4:57
  • That seems like a strange setup. Is this some form of corporate setup? If so you should highlight this as an issue. In either case, I would look into using a credential helper instead of trying something like this. git-scm.com/book/en/v2/Git-Tools-Credential-Storage Commented Apr 25, 2022 at 4:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.