3

Is there a monitor like top but for the w (who) command? It's ok if it's a package that needs to be installed. Any Linux flavor. I'd like to have a simple CLI real-time monitor of users logged into the system along with what they're doing. TIA

0

2 Answers 2

4

You have several possibilities. Those that come to my mind immediately are all based in the idea to periodically execute the w command (hence, strictly speaking they are no real-time monitors, but top also refreshes the current processes only periodically):

  1. Shell based (bash syntax)

    Infinite loop that executes w every second:

    while true; do
       clear
       w
       sleep 1
    done
    
  2. There's also a dedicated program for that purpose, called watch:

    watch -n 1 "w"
    
  3. While possibility 1 and 2 usually work out-of-the-box on a standard GNU/Linux system, there is also a program called multitail. Although in the first place designed for another purpose,

    The program MultiTail lets you view one or multiple files like the original tail program. The difference is that it creates multiple windows on your console (with ncurses). It can also monitor wildcards: if another file matching the wildcard has a more recent modification date, it will automatically switch to that file.

    it can also execute a program periodically:

    multitail -r 1 -l "w"
    

Both, watch and multitail can also highlight the differences compared to the previous run, please check the man pages for the corresponding (and much more) options.

2
  • Perfect, thanks! I had already been doing #1 but figured there might be a better tool. I like finding out about the other options, thanks again!
    – mVChr
    Jun 16, 2015 at 18:08
  • eol="$(tput el)";clear; while true ; do w | sed -re "s/^(.*)$/$eol \1 /" ;sleep 1 ; tput home ; done - a variant for the first above.
    – Hannu
    Jun 16, 2015 at 20:45
1

The last command acts by reading /var/log/wtmp. You can set up a watch on it by means ofinotifywait(part of the package *inotify-tools) as follows:

   while inotifywait -e close_write /var/log/wtmp ; do /path/to/executable/script; done 

where /path/to/executable/script is some a script (made executable by chmod 755 script) which will do some highly noticeable action to attract your attention, see here for some suggestions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .