如何削减从Linux命令&QUOT子;谁" [英] how to cut substring from linux command "who"

查看:162
本文介绍了如何削减从Linux命令&QUOT子;谁"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命令的返回登录到服务器的用户列表

  [管理员@ DB01ATK〜] $谁
adm_drodmann分/ 3 2015年7月1日08:57(10.129.12.77)
adm_ssmith点/ 4 2015年7月1日02:11(10.129.12.76)
adm_kholdman分/ 2 2015年6月30日23:08(10.129.12.45)

问题是分配给变量,用户名($ 1),其中终端($ 2)是命令结果的值

 的ps aux |屏幕的grep


解决方案

按<一个href=\"http://stackoverflow.com/questions/31155684/how-to-cut-substring-from-linux-command-who/31156251?noredirect=1#comment50331100_31156251\">your评论我扩大我的解决方案。你想说:

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

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

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)

这篇关于如何削减从Linux命令&QUOT子;谁&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆