且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何削减从Linux命令&QUOT子;谁"

更新时间:2023-02-15 21:15:00

按your评论我扩大我的解决方案。你想说:

  PTW = $(的ps aux | awk的'/屏幕/ {$打印7})
而IFS =读-r用户资源_;

    [$ RES=$ PTS]&放大器;&安培;回声记录为$ USER
完成< ≤(谁)

command who returns list of users logged to server

[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)

the point is to assign to variable, value of username($1) where terminal($2) is result from command

ps aux | grep screen

As per your comment I expand my solution. You want to say:

ptw=$(ps aux | awk '/screen/ {print $7}')
while IFS=read -r user res _;
do 
    [ "$res" = "$PTS" ] && echo "logged as $user"
done < <(who)