0

I am trying to create a script that would login to each server from a list with a user from other list and execute a command. How can I do this by taking the first host from the file and login with the first user from another file, take the second host from the file and login with the second user from the file and so on?

This is what I got so far:

#!/bin/bash
for host in `cat hosts.txt`
do
for user in `cat users.txt` ;
do
ssh -t Natasha@$host << EOF ;
/usr/local/bin/sudo -i -u $user w ;
EOF
done
done

But this is executing the command for the first host with all the users from the users list.

1 Answer 1

2

if there are same number of line in both file

paste hosts.txt users.txt |
while read host user
do
   ...
done

you can try paste command first to check host get their proper user.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.