【发布时间】:2010-10-06 13:48:41
【问题描述】:
import pwd
import operator
# Load all of the user data, sorted by username
all_user_data = pwd.getpwall()
interesting_users = sorted((u
for u in all_user_data
if not u.pw_name.startswith('_')),
key=operator.attrgetter('pw_name'))
# Find the longest lengths for a few fields
username_length = max(len(u.pw_name) for u in interesting_users) + 1
home_length = max(len(u.pw_dir) for u in interesting_users) + 1
# Print report headers
fmt = '%-*s %4s %-*s %s'
print fmt % (username_length, 'User',
'UID',
home_length, 'Home Dir',
'Description')
print '-' * username_length, '----', '-' * home_length, '-' * 30
# Print the data
for u in interesting_users:
print fmt % (username_length, u.pw_name,
u.pw_uid,
home_length, u.pw_dir,
u.pw_gecos)
上述程序从 linux 密码文件中获取密码, 我想创建显示维护用户登录日志的 linux 内核文件的程序。 如何进入内核请帮忙.......
【问题讨论】:
-
我为您格式化了代码。下次请看预告。它是“内核”,而不是“内核”。顺便说一句,您的问题不清楚。
-
"如何进入内核" -- 比如... Tron?
-
代码与问题无关。
-
维护用户登录日志的linux内核文件 huh?
-
我已经修改了问题,请看一下........