-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsmartd-create-super-users-desktop-file
More file actions
executable file
·44 lines (31 loc) · 1.11 KB
/
smartd-create-super-users-desktop-file
File metadata and controls
executable file
·44 lines (31 loc) · 1.11 KB
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
40
41
42
43
44
#!/usr/bin/env python
import grp
import os
import pwd
from datetime import datetime
from plumbum import local
SUPER_USER_GROUPS = ['root', 'wheel', 'sudo']
ENCODING = 'UTF-8'
def get_user_group_names(uid):
user = pwd.getpwuid(uid)
return [grp.getgrgid(g).gr_name for g in os.getgrouplist(user.pw_name, user.pw_gid)]
def get_super_users():
super_users = []
for user in pwd.getpwall():
groups = get_user_group_names(user.pw_uid)
if any(group in SUPER_USER_GROUPS for group in groups):
super_users.append(user)
return super_users
def main():
super_users = get_super_users()
for user in super_users:
# Skip root account, since it is almost never used directly
if user.pw_uid == 0:
continue
path = os.path.join(user.pw_dir, 'Desktop', 'S.M.A.R.T. Failure.txt')
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, 'a', encoding=ENCODING) as file:
file.write(datetime.now().isoformat() + ':\n')
file.write(local.env['SMARTD_FULLMESSAGE'] + '\n\n')
if __name__ == '__main__':
main()