0

I'm trying to write a script to loop through two different lists :

list 1 : list of servers
list 2 : list of users

I want to loop through the list of servers in list 1 and check the status of the user accounts in list 2 on each server.

This is what I have so far, but the inner loop is only checking the first account in the list on each server, then going back to the "outer loop" of servers. So I'm halfway there, I guess?

This is my script so far:

#!/bin/bash

unset SERVER
unset USER

while IFS= read -r SERVER; do
        echo "$SERVER"
        while IFS= read -r USER; do
                 ssh "$SERVER" "/usr/bin/lastlog -u $USER"
        done < /path/to/list_of_users.lst
done < /path/to/list_of_servers.lst

I can't seem to figure out where I'm going wrong here. Any advice would be appreciated!

Andi
  • 51
  • 1
  • 1
  • 3
  • 2
    Have you tried with `ssh -n`? (for not consuming the stdin) – thanasisp Dec 15 '20 at 19:53
  • 2
    Possibly related: [Using while loop to ssh to multiple servers](https://unix.stackexchange.com/questions/107800/using-while-loop-to-ssh-to-multiple-servers) – steeldriver Dec 15 '20 at 19:59
  • Check out the comments above regarding embedding ssh within a while loop, but in short, ssh interferes with STDIN. – Scot Dec 16 '20 at 02:40

0 Answers0