I'm looking to list all files in a folder:
ABC123.cfg
XYZ456.cfg
EFG999.cfg
The file names, without the .cfg
relate to a remote server name, ABC123
etc.
I want to copy a couple of files to each of the remote servers.
So, look up the filenames, but take the name without the .cfg
. Then
scp filename.txt username@ABC123:/home/username/
For each remote server, overwriting the destination file if exists.
Each remote server uses the same username and password.
Can I use a password in the scp
command?
This should do the job:
or rather
The password is passed to
scp
usingsshpass
(following How to pass password to scp?) which reads it frompasswordfile
– remember to secure this file against unauthorized read access withchmod 400
!I got a little bit confused what file you want to send here, I understood there's e.g. a file
ABC123.txt
that has to be sent to hostABC123
, so I just stripped.cfg
using Bash Parameter Expansion and added.txt
.As
user@host:
defaults touser
's home directory I removed the path.