You are here

Save a list of users and the groups they belong to, to a file.

Last modified: 
Sunday, December 14, 2014 - 14:20


Create a new file, save_UsersAndGroups.sh
Make your newly created file executable
Terminal
name@machine:/$ sudo chmod +x /path/to/save_UsersAndGroups.sh

Copy the code posted here to save_UsersAndGroups.sh then save.

#!/bin/bash
 
# 0 will list off /home/UserName's
# 1 will list off all user accounts (www-data, mysql, daemon, syslog, etc.)
allUsers=1;
 
 
if  ; then
	cat /dev/null > 'UsersAndGroups.log';
fi
 
 
if  ; then
	gawk -F: '{ print $1 }' /etc/passwd > 'UsersAndGroups.log';
else
	ls /home > 'UsersAndGroups.log';
fi
 
num=0
for user in `cat UsersAndGroups.log`; do
	users[$num]=$user;
	num=$(($num + 1))
done
cat /dev/null > 'UsersAndGroups.log';
 
users_count=${#users[@]};
for (( i=0;i> 'UsersAndGroups.log';
	#groups ${users[${i}]};
done
Mobile QR Barcodes: 
Save Article as PDF
Current URL Address
Category: 

Add new comment