命令谁返回登录到服务器的用户列表
[admin@DB01ATK ~]$ who
adm_drodmann pts/3 2015-07-01 08:57 (10.129.12.77)
adm_ssmith pts/4 2015-07-01 02:11 (10.129.12.76)
adm_kholdman pts/2 2015-06-30 23:08 (10.129.12.45)
关键是要分配给变量,用户名($ 1)的值,其中terminal($ 2)是命令的结果
ps aux | grep screen
最佳答案
问题回答的问题:
PTS=$(awk '{print $7}' <<< $(ps aux | grep screen) )
who | while read CMD;
do
res=$(awk '{print $2}' <<< "$CMD")
if [ "$res" = "$PTS" ]
then
echo "logged as $(awk '{print $1}' <<< "$CMD")"
fi
done;
:-)
关于linux - 如何从Linux命令“谁”削减子串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31155684/