0

I am trying to find a way to connect to a list of servers written in a simple textfile to run one command and write the output to a file... The small problem is, I have to login with a password... but it would not a problem to paste the password into the script. the full command would be:

ssh "server_from_list.txt uptime | awk -F, '{sub(".*up ",x,$1);print $1}' >> /home/kauk2/uptime.out

lets assume the password is: abcd1234

Any suggestions??? I am not fit in scripting, sorry... Many thanks to you all in advance...

regards, Joerg

  • see https://stackoverflow.com/questions/4780893/use-expect-in-bash-script-to-provide-password-to-ssh-command – Jetchisel Mar 19 '20 at 10:24

1 Answers1

0

Ideally you should set up password-less login, but failing that you can use sshpass. First, get a single command working by trying the following:

export SSHPASS=abcd1234

Then you can try:

sshpass -e ssh user@server1 'uname -a'

When you get that debugged and working, you can use GNU Parallel to run the command on all servers in a file called list.txt

user@server1
user@server2
user@server3
user@server4

The command will be:

parallel -k -a list.txt sshpass -e ssh {} 'uptime'
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Hi Mark, thanks for your suggestion. I forgot to say, I am working in an IBM AIX environment. So, no sshpass is available here... – Jörg Kauke Mar 20 '20 at 11:45