【问题标题】:How to extract a column value from a command output in shell script如何从 shell 脚本的命令输出中提取列值
【发布时间】:2021-09-07 21:31:00
【问题描述】:

我正在尝试编写一个 shell 脚本,我想在其中终止 fuser 命令给出的进程列表。

给出fuser 的输出。我想杀死列出的 pids

kill -9 157909 1504107 1504111 1504112 2690311 3206490

我该怎么做?

【问题讨论】:

  • 使用awk。但请注意,列号取决于该行是以端口号还是空格开头。

标签: linux shell terminal script


【解决方案1】:
   -k, --kill
         Kill processes accessing the file.  Unless changed with -SIGNAL,
         SIGKILL is sent.  An fuser process never kills itself,  but  may
         kill  other  fuser  processes.   The  effective  user  ID of the
         process executing fuser is  set  to  its  real  user  ID  before
         attempting to kill.

fuser -k 会做到的。

【讨论】:

    【解决方案2】:

    ps -u 珠子 | awk '{打印 $2}' |而读线;杀死 -9 $line;完成

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-02
      • 1970-01-01
      • 1970-01-01
      • 2014-09-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多