Reputation: 794
I am trying to make a script that will sync with another folder over a ssh connection. What I want to do is sync my local folder with the folder over ssh and then perform an ssh login. For these two commands I need to enter the same password and it's a little annoying so I am trying to make a script for it to put my password into a temporary variable and pass that variable to the two spots it is requested. This is what I have.
read -s -p "Enter Password: " mypassword && echo "$mypassword"
| rsync -vz -r `~/Desktop/Market_Maker/Market_Maker [email protected]:~/281_Projects
&& echo | "$mypassword" ssh [email protected]`
What this ends up doing is gives me 3 password prompts and does not work at all. What is wrong with the script?
Upvotes: 0
Views: 755
Reputation: 683
Consider using sshpass
to store your password for a specific login. Once installed you can run the command:
sshpass -p 'PASSWORD' ssh [email protected]
to login to the server. I think that might be the functionality you are looking for. You might also consider setting the RSYNC_PASSWORD
variable to be the password in the script.
If you want to avoid storing your password in the script you can prompt for it using:
read -s RSYNC_PASSWORD
This will store the password for the duration of the scripts execution.
Upvotes: 2