bash's who command
I'm trying to capture&analyze the IDLE time for users in a python script, as obtained by the who command.
My problem is that who's time output is a mess - some examples given:
1.00s
47:49
-
9days
... and I possibly left out some of them. There is some way of converting it to something that can be analysed easier? Or where do I find the documentation on this time format?
An additional question: since I'm cross-developing my prog on linux and osx, I found out that OSX's who has an additional '-i' switch, which orders output by idle time. Since I need to find the most recently executed shell command, do you know if on linux something simil开发者_StackOverflow社区ar to 'who -i' exists?
thank you!
a word to clarify: my script at the end returns the current working directory of the terminal that executed last.
I didnt find a more elegant way to do it than to execute in sequence the commands:
ps e -o pid,tty,comm (to find the bash'es)
ls -l /proc/'+pid+'/cwd' (to find the CWDs)
w (to sort by time)
... so 'w' is needed last to find which shell'cwd to return
Python's os module really has such a function. It's called getlogin()
, see here: http://docs.python.org/library/os.html#os.getlogin
Regarding your update:
There is also a getcwd()
available: http://docs.python.org/library/os.html#os.getcwd
But I'm not fully understanding what you are really trying to do, so I can't tell whether this two functions is all you need.
精彩评论