简体   繁体   English

如何尾随w命令

[英]how to tail the w command

is there a way to track who has logged in or out in real time. 有没有一种方法可以实时跟踪谁已登录或注销。 At the moment I run w but it exits as soon as it is done. 目前,我运行w,但一旦完成它就会退出。 I am thinking there might be some way to tail the w command or run it continuously. 我在想可能有某种方法可以拖尾w命令或连续运行它。

您可以尝试以下命令:

watch -n1 w

login/logout info is stored at /var/log/wtmp* also ( http://linux.about.com/library/cmd/blcmdl5_wtmp.htm ) 登录/注销信息也存储在/var/log/wtmp*http://linux.about.com/library/cmd/blcmdl5_wtmp.htm

you can get those info by watch last 您可以通过watch last获得这些信息

You could run it in a infinite while loop, and throw off prompts whenever a new user enters. 您可以在无限的while循环中运行它,并在新用户进入时抛出提示。

#!/usr/bin/bash
b=`w|cut -d' ' -f1`;
while (true)
    do
        a=`w|cut -d' ' -f1`;
        if [ "$b" != "$a" ]
            then
            echo "new user!";
        fi
        b=$a;
    sleep 1;
    done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM