0

I have written a shell script to clone the project from multiple location which is sent as a file. I read the file and pass the each location in a loop and perform my operation.

LocationFile.txt

Project1=https://[email protected]/my/path/testProject1.git
Project2=https://[email protected]/my/path/testProject2.git
Project3=https://[email protected]/my/path/testProject3.git
Project4=https://[email protected]/my/path/testProject3.git

Password.txt

Project1=password1
Project2=password2
Project3=password3
Project4=password4

I have a password file encrypted and stored in server, which I can read as part of script and passing into my script When I run my script during clone step its prompting for a password, I tried to pass the password like below which is not working

##############
gitpassword=$password1 #retrieved from Password.txt

for xxx
    do
    ...
    ... 
    git clone "${ProjectArrayList[1]}" 
    read $gitpassword
    ...
    ..
    done
##############

I know I can do password less if I use ssh, which I don't want to do. Is there a way to achieve this with my exsiting approach

2 Answers 2

2

You can use the expect and send functions to simulate user input automatically.

Here is what the syntax would be like:

expect -c 'spawn sudo git clone "${ProjectArrayList[1]}"; expect assword; send "password\n"; interact'
Sign up to request clarification or add additional context in comments.

Comments

1

Git has a "credential helper" that can do the job [it is designed to work over https].

See: https://git-scm.com/docs/git-credential-store and https://help.github.com/articles/caching-your-github-password-in-git/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.