In this assignment, we write a program which will return a list of all users present in the system who can do a proper login.
The code for the above problem can be found here
Here is the solution to the problem
!/usr/bin/env python import pwd total_list = pwd.getpwall() # a list of all password database entries for i in total_list: # iterating throgh the list if i[5].find("home") == 1: # if 'home' is present in the user home directory print i[0] # print the user name if i[5].find("root") == 1: # if 'root' is present in the user home directory print i[0] # print the user name
We shall save the above code as "user finder.py". To run the script, follow the steps.
Change the file's permissions and make it executable:
$ chmod +x user\ finder.py
Execute the file:
$ ./user\ finder.py
Alternatively, try:
$ python user\ finder.py