4 of 6
added 337 characters in body
dessert
  • 39.7k
  • 12
  • 116
  • 165

That should do the job:

for i in *.cfg; do
  sshpass -p "password" scp ${i%.cfg}.txt username@${i%.cfg}:
done

The password is passed to scp using sshpass following How to pass password to scp? – remember to secure the file against unauthorized read access with chmod 700 if you store a password in plain text!

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 host ABC123, so I just stripped .cfg using Bash Parameter Expansion and added .txt.

As user@host: defaults to user's home directory I removed the path.

A little more secure approach (thanks to pa4080!) would be to make it a script and give it the passwort as the first argument, this way you don't need to store it in plain text:

#!/bin/bash
for i in *.cfg; do
  sshpass -p "$1" scp ${i%.cfg}.txt user@${i%.cfg}:
done
dessert
  • 39.7k
  • 12
  • 116
  • 165