I am working on a project where, I have to get logoff, logon, lock, unlock, console connect, disconnect, service start/stop using python. Can anyone help me regarding this.
Asked
Active
Viewed 442 times
1
-
Are you talking about operating system event logging? Meaning, the timestamps when a user logs on or off interactively? – Daniel Pryden Feb 04 '19 at 14:16
-
`start/stop using python`, I thought he was referring to the use of python but I got downvoted so I guess he just wants the last boot time, login time,... – Benoît P Feb 04 '19 at 14:20
-
If you don't give us more details, we won't be able to answer your question correctly. – Benoît P Feb 04 '19 at 14:29
-
@DanielPryden, ya you are right, but using python – Ashok Kumar Rai Feb 04 '19 at 14:31
-
@BenoîtPilatte, the thing is that I want to track the employee activity like when they are going for break and how long i.e lock and unlock time with user name. similarly logon and logoff time for the user using python. – Ashok Kumar Rai Feb 04 '19 at 14:34
-
The thing is, macOS doesn't run on Python so you will have to interact with the system somehow anyway. – Benoît P Feb 04 '19 at 14:36
-
Note that extensive tracking of employee activity is illegal in a lot of countries. – Benoît P Feb 04 '19 at 14:38
-
@BenoîtPilatte Actually I m absolute beginner and need to make it as a service or convert in .exe file – Ashok Kumar Rai Feb 04 '19 at 14:39
-
You can check my answer, it goes in details on two possibilities you have. They can be used in Python but you must have a basic knowledge of the way macOS handles users and how to parse a command output or a file. – Benoît P Feb 04 '19 at 14:43
1 Answers
0
You can use the last UNIX command and call it from within python.
It will give you logoff, logon, console connect/disconnect, boot, reboot, shutdown. last Jhon to see Jhon's history, last reboot to see reboot history.
You can also use the ~/.zsh_history or ~/.bash_history file if you want to see the use of the console, it contains timestamps relative to EPOCH time. It might be better than raw login/logoff times since you can have an open prompt and type nothing in it.
Benoît P
- 2,744
- 12
- 30
-
Pilatte, Last command is producing reboot and shutdown, But I need switch user activity (i.e when users are changing their shift) – Ashok Kumar Rai Feb 05 '19 at 06:16
-
`last jhon` gives you all login history for `jhon`, which is what you want. – Benoît P Feb 05 '19 at 13:18
-
Pilatte, Thanks for your quick reply, it's working like charm. CAN you suggest something similar for screen lock/Unlock – Ashok Kumar Rai Feb 06 '19 at 10:09
-
To my knowledge, that is not recorded. Simply because there is no such thing as screen locked/unlocked to the kernel. – Benoît P Feb 06 '19 at 10:28
-