#---------------------------------------------------------
# Print days diff by Converting Unix timestamp to Readable Date/time
#---------------------------------------------------------
def convUnixTime(t):
return 1+(datetime.datetime.fromtimestamp(t*60*60*24)
- datetime.datetime.today()).days
#---------------------------------------------------------
# Read shadow file and check for account expires and create dictionary
#---------------------------------------------------------
with open( "/etc/shadow" ) as shadow:
for aLine in shadow:
filed = aLine.split(":")
f = filed[7]
try:
f = int(f)
f=convUnixTime(f)
except ValueError:
f = "NULL"
if f != "NULL" and f <= 0:
total_expired_users += 1
expr_list[ filed[0] ] = f
elif f != "NULL" and f <= min_days:
total_expring_users += 1
expr_list[ filed[0] ] = f
我已经创建了用户的字典,其中帐户已经过期,但我认为这已经做了更干净和简单的方式。。在
提前谢谢!!在
使用try-except子句,这可能看起来更干净:
您也可以稍微更改顺序,以避免
^{pr2}$expr_list[filed[0]]
重复:谢谢贝雷尔
在你的纠正下,我已经创造了最终的。。在
分析完整个Script。。 输出:
^{pr2}$您可以使用列表理解来简化代码:
相关问题 更多 >
编程相关推荐