Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi , I am using the Net::SSH::Perl Module to execute the "w" command on the remote machine . I am getting the result on the display screen after executing my perl script as shown below.
USER TTY FROM LOGIN@ IDLE JCPU PCPU root tty1 - 6:28am 1:04 1.04s 0.02s man tty2 - 6:28am 15:59 0.05s 0.03s jen tty3 - 6:28am 15:55 0.17s 0.05s
But I want to search only for root priviledged user's from the "w" command ."w" command lists all the user's who are logged to the remote machine including those without root priviledges.Like in the result shown above user "man" is not root priviledged user. How can I do that using the "w" command results. Also I want to search in the sshd.log or the messages log files so that i can get the disconnect time for the particular user who has logged out . Here is an example to illustrate what I want to achieve using Net::SSH::Perl module : If "w" output shows 3 user's logged in to the remote machine like the one shown above then I want to first check whether the user "man" is root priviledged or not .If the user "man" is root priviledged user then I want to search in the sshd.log or messages log files to remove the time of connect and disconnect time for the user "man". If the user "man" is not root priviledged user then no search is to be performed . Same with the user "jen" . How can I add a column to the above result to show the user disconnect time . I want the final display like :
USER TTY FROM LOGIN@ IDLE JCPU PCPU Disconnect root tty1 - 6:28am 1:04 1.04s 0.02s 6:45am man tty2 - 6:28am 15:59 0.05s 0.03s 7:10am jen tty3 - 6:28am 15:55 0.17s 0.05s 6:30am
I tried using grep and cut but with no success. Please suggest me on the above problem . Thankyou !

Replies are listed 'Best First'.
Re: Net::SSH::Perl Help
by waswas-fng (Curate) on Jul 31, 2003 at 15:55 UTC
    I don't get it, if there is a ssh disco logged the user would not show up in "w" anyways. You seem to be using the wrong tools for the job. take a look at sys::utmp -- it has all the stats you want on most unix systems and you can build your full report from there.

    -Waswas