Looking for a perl/python programmer to help me out.

Discussion in 'Programming' started by Arkserver, Jan 28, 2007.

  1. #1
    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.
     
    Arkserver, Jan 28, 2007 IP
  2. tandac

    tandac Active Member

    Messages:
    337
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #2
    The commands: w, ps and du will give you the information you seek.
     
    tandac, Jan 28, 2007 IP
  3. Arkserver

    Arkserver Banned

    Messages:
    2,533
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Any idea how i can make a script out of it so it will when i log in with ssh?
     
    Arkserver, Jan 28, 2007 IP
  4. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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
     
    picouli, Jan 29, 2007 IP
  5. Arkserver

    Arkserver Banned

    Messages:
    2,533
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.
     
    Arkserver, Jan 29, 2007 IP
  6. bigspaces

    bigspaces Guest

    Messages:
    105
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Check out the pexpect module for this kind of scripting. Otherwise, you can just try using the "popen"'s and "system".
     
    bigspaces, Mar 19, 2007 IP
  7. serjio28

    serjio28 Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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):
     
    serjio28, Mar 20, 2007 IP