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.