Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Problem :
I have to transfer a file to many maschines.
I do not want to use key pairs, but scp.
How do I pass the password into the script? I do not mind that password stands in a script, it is OK.
I know about EXPECT, and have made it work, but only for one loop (see below)and I need it to work on 20 maschines....
Help would bne greatly valued!
My scripts :
With EXPECT :
*************************
set nalog username
set lozinka password
set fajl bla-bla
spawn scp -p -v /root/nalog/$fajl $nalog@10.66.3.222:/home/$nalog
expect "$nalog@IP address's password:"
send "$lozinka\r"
interact
**************************
When I try to make another (same definition) process towards another maschine, it does not work any more. So how do I make multiple scp-s with EXPECT (all different IP, username and pass)?
With SCP :
**************************
nalog=username
lozinka=pasword
echo Name of the file to transfer :
echo $fajl
scp -2 -4 -v /root/nalog/$fajl $nalog@IP address:/home/$nalog
*************************
When I try to make the script take the password here (and belive me, I have tried echo, piping, etc) it does not work any more
but this won't work because scp doesn't read from the standard input because is designed not to allow the user to do things like pass the password through standard input.
You might want to read up on using ssh-agent and ssh-add for this. The idea is that you just need to supply your password once when you start your session. It is more secure doing this to cache your passphrase, then passwordless logins, in the case that one of the remote servers is compromised or you don't trust the root user on that server.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.