I have a file server.txt containing different hostnames like:
My shell script servers.sh is written to get the /etc/passwd and /etc/group files from the list in servers.txt file.
I wish to add the hostname from which the entries came from in my final output file. My script looks something like below:
The goal is to add another column in both
and
like
so I can know which servers each entry came from.
Code:
hostname1.com
hostname2.com
My shell script servers.sh is written to get the /etc/passwd and /etc/group files from the list in servers.txt file.
I wish to add the hostname from which the entries came from in my final output file. My script looks something like below:
Code:
while read HOST ;
do
sshpass -p $password ssh -n $username@$HOST 'cat /etc/passwd'>>users.txt
sshpass -p $password ssh -n $username@$HOST 'cat /etc/group'>>groups.txt
done < servers.txt
echo -e "UserName;UID;GID;HomeDir;Shell" > final_users.csv
cut -d: -f1,3,4,6,7 users.txt | tr ':' ';'>> final_users.csv
echo -e "GroupName;GID;Members" > final_groups.csv
awk -F '' '{for(i=4;i<=NF;i++)print$1";"$3";"$i}' groups.txt >> final_groups.csv
The goal is to add another column in both
Code:
final_users.csv
Code:
final_groups.csv
Code:
hostname