How to automatically load password in bash script using ssh login process
Hello, I have written a bash script that includes two do while loops. The inner loop is designed to compare a list of file names, one file at a time, against a remote server (identified in the loop). The inner loop requires ssh authenticatin against the remote server. Can anyone tell me what I need to do to automate the process of entering the password each time the inner loop attempts to login to the remote server and perform the comparrison?
Thanks in advance for your assistance. #!/bin/bash # # ServerName=/path-name/master-server-list.txt IdAMName=/path-namec/master-file-list.txt while read filename do outfile=/path-name/log-file-name.log date >> $outfile 2>&1 echo $filename >> $outfile 2>&1 while read filename1 do sleep 15 ssh -n <username>@$filename "cat $filename1" | diff - $filename1 >> $outfile 2>&1 echo $filename1 >> $outfile 2>&1 echo $infile1 echo $filename echo $infile echo $filename1 done < $IdAMName done < $ServerName # End of script |
The best and easiest way to achieve your goal would be to not use password based authentication on the server, but key-based authentication. This way you don't need to think about putting in passwords.
If you really need to do it with passwords (may be because you can't change the servers configuration) usually special script languages like Expect are used to react to script input/output and make things possible like automated password input. http://www.nist.gov/el/msid/expect.cfm |
TobiSGD, I appreciate the response, but there are a couple of reasons that I need to accomplish this with a password. Any ideas?
|
Depending on what your ultimate goal for this comparison is, your might want to investigate using "rsync" with the "--itemize_changes" option.
|
Quote:
|
Quote:
Quote:
Let me be Captain Obvious here. It is extremely insecure to put passwords in shell scripts, no matter the "reason". Those who sacrifice Security for Convenience have neither. |
Quote:
Have a look here: http://bash.cyberciti.biz/security/e...-login-script/ |
All times are GMT -5. The time now is 01:31 AM. |