Hi, I'm currently running linux and i want to know how many users are logged in and how much resource they are using. Is there a way to make this in perl/python? Hints or sample code is appriciated. I have no idea how to make this in perl or python because i'm not a perl/python programmer but i do want to know how many users are logged in a linux server and the resource they are using. Thanks.
Do you want to periodically store it in a DB (so that you can check it later) or you just want to see it when you log in? In this case, just typing 'w' at the prompt will show you how many users are logged in, while 'uptime' and 'top' will show various info on the system (do a 'man uptime' and 'man top' to read more about this) HTH, cheers
Thanks, I already knew of the commands but i want it to show the info automatically after i'm logged in the system. This would be easier instead of doing everything manually. No need to store it in a DB. A perl or python scripts that can perform this task would be very appriciated. I prefer python because I'm trying to learn this language so I can make this script and now i know the syntax a little bit I can create a simple script but not enough to make this scripts on my own.
Check out the pexpect module for this kind of scripting. Otherwise, you can just try using the "popen"'s and "system".
I know the Perl only. Please look at the possible solution. #!/usr/local/bin/perl $users = $1 if(`w` =~ /(\d+)\s+users/i); $load = $1 if(`w` =~ /load\s+average:\s+(\d+,\d+)/i); printf("users:%d load:%s\n",$users,$load); Code (markup):