#---------------------------------------------------------
# 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
我创建的用户是哪个帐户已到期的字典,但我认为这更多的清洁和简单的方式已经完成..提前的Python:创建字典
谢谢!
Python是一个奇怪的语言 - 它使用一本字典作为地图。不要试图在现实生活中做到这一点! :) – NoBugs
@NoBogs这是什么影响? –
在现实生活中使用字典作为地图根本无济于事,它只会让人迷失方向。 – NoBugs