-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_nobash.py
More file actions
41 lines (28 loc) · 777 Bytes
/
user_nobash.py
File metadata and controls
41 lines (28 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'''
Author : Ashutosh Kumar
PRN : 19030142009
Assignment: Read all the usernames from the /etc/passwd file and list users
which do not have bash as their default shell
'''
fp = ""
try:
# opening file in read mode
fp = open('/etc/passwd', 'r')
# extracting every user from the file
for line in fp:
# writing it to the new file
if 'bash' not in line:
print(line.split(':')[0])
except FileNotFoundError:
print("File not Found ")
except FileExistsError:
print("File Already Exists")
except PermissionError:
print("Permissison to open file is not granted ")
except IsADirectoryError:
print("It is a directory")
finally:
try:
fp.close()
except AttributeError:
print("File not opened ")