wcusersdata

wcUsersData

Script to get users logged into the system.

Saves the output of users as the hostname of the system. Convert to a dict and json object, merging with other hostname output.

Runs script every min and if user is found then - time from their account

File with, usernames, time remaining on user.

time file is a json object. {'username' : 'wcmckee', 'time' : 320 }

time is amount of time left on account.

script to check this object and if 0 - lock account. ELSE, allow login.

Script to add time to acoun,, auto add time to certain groups/user a day.

username 45

In [5]:
import os
import socket
import json
In [6]:
usertimedict = dict()
In [7]:
lisho = os.listdir('/home')
In [8]:
for ish in lisho:
    usertimedict.update({ish : 0})
In [9]:
usertimedict
Out[9]:
{'blag': 0,
 'blah': 0,
 'charle': 0,
 'checkthis': 0,
 'clittle': 0,
 'figlet': 0,
 'gerty': 0,
 'jblog': 0,
 'jchick': 0,
 'joecheck': 0,
 'joeman': 0,
 'joemanz': 0,
 'pjohns': 0,
 'poi': 0,
 'point': 0,
 'poiu': 0,
 'pytest': 0,
 'qwe': 0,
 'red': 0,
 'signinlca.py': 0,
 'sjohns': 0,
 'ssung': 0,
 'tnow': 0,
 'wblack': 0,
 'wcm': 0,
 'wcmckee': 0,
 'webmck': 0,
 'wez': 0,
 'wkee': 0,
 'wmen': 0}
In [10]:
addtime = (raw_input('add how much time: '))
add how much time: 15
In [11]:
#letim = len(addtime)
In [12]:
#letim
In [13]:
addtime
Out[13]:
'15'
In [14]:
type(addtime)
Out[14]:
str
In [15]:
intime = int(addtime)
In [16]:
for ish in lisho:
    usertimedict.update({ish : intime})
In [17]:
usertimedict
Out[17]:
{'blag': 15,
 'blah': 15,
 'charle': 15,
 'checkthis': 15,
 'clittle': 15,
 'figlet': 15,
 'gerty': 15,
 'jblog': 15,
 'jchick': 15,
 'joecheck': 15,
 'joeman': 15,
 'joemanz': 15,
 'pjohns': 15,
 'poi': 15,
 'point': 15,
 'poiu': 15,
 'pytest': 15,
 'qwe': 15,
 'red': 15,
 'signinlca.py': 15,
 'sjohns': 15,
 'ssung': 15,
 'tnow': 15,
 'wblack': 15,
 'wcm': 15,
 'wcmckee': 15,
 'webmck': 15,
 'wez': 15,
 'wkee': 15,
 'wmen': 15}
In [19]:
myhn = socket.gethostname()
In [37]:
#Edit just one person

edione = raw_input('Which user to edit time: ')
timedi = raw_input('How much time to add: ')

usertimedict.update({edione : timedi})
Which user to edit time: point
How much time to add: 100
In [20]:
jstim = json.dumps(usertimedict)
In [21]:
jstim
Out[21]:
'{"wcmckee": 15, "joemanz": 15, "point": 15, "qwe": 15, "wkee": 15, "checkthis": 15, "poiu": 15, "blah": 15, "charle": 15, "poi": 15, "tnow": 15, "clittle": 15, "wblack": 15, "ssung": 15, "wmen": 15, "blag": 15, "signinlca.py": 15, "sjohns": 15, "gerty": 15, "webmck": 15, "joeman": 15, "joecheck": 15, "jchick": 15, "pytest": 15, "jblog": 15, "pjohns": 15, "wez": 15, "figlet": 15, "wcm": 15, "red": 15}'
In [24]:
opus = open('/home/wcmckee/sellcoffee/hostnames/' + myhn, 'w')

opus.write(jstim)
opus.close()
In [26]:
rdopuw = open('/home/wcmckee/sellcoffee/hostnames/localhost', 'r')

print rdopuw.read()
{"wcmckee": 15, "joemanz": 15, "point": 15, "qwe": 15, "wkee": 15, "checkthis": 15, "poiu": 15, "blah": 15, "charle": 15, "poi": 15, "tnow": 15, "clittle": 15, "wblack": 15, "ssung": 15, "wmen": 15, "blag": 15, "signinlca.py": 15, "sjohns": 15, "gerty": 15, "webmck": 15, "joeman": 15, "joecheck": 15, "jchick": 15, "pytest": 15, "jblog": 15, "pjohns": 15, "wez": 15, "figlet": 15, "wcm": 15, "red": 15}
In [33]:
edione
Out[33]:
'point'
In [34]:
limedi = int(timedi)
In [35]:
limedi
Out[35]:
15
In [9]:
osscm = ('users > ' + myhn + '.txt')
In [11]:
osscm
Out[11]:
'users > naplesyellow.txt'
In [ ]:
 
In [ ]:
 
In [12]:
os.chdir('/home/wcmckee/sellcoffee/')
In [13]:
os.system(osscm)
Out[13]:
0
In [14]:
ophos = open('/home/wcmckee/sellcoffee/' + myhn + '.txt')
In [15]:
print ophos.read()
Out[15]:
'noby wcmckee wcmckee wcmckee wcmckee wcmckee\n'
In [17]:
ophos.close()
In [ ]:
 
In [ ]:
 

Comments

Comments powered by Disqus