I am on an AWS instance and have need to make a list of all the usernames on this instance. Something simple like:
ls /home > users.txt
would suffice, but I then need to go through each name and check its PID number, from there if the user doesn't have a PID number (ie a non zero return value) then I would like to delete it from the users text file i created.
I have tried the following, but received many errors:
#!/bin/bash
ls /home > users_inc.txt
while read line
do
id -u $line
if [$? -e 0]
then
echo $line > users.txt
fi
done < users_inc.txt
Fairly new to bash scripting, any help would be appreciated.