我必须每天多次做同样的事情:
ps aux
寻找对我的一台服务器运行 ssh 的进程 ...
kill -9 <pid>
我正在查看是否可以将流程别名化为一行。 ps aux 的输出通常是这样的:
user 6871 0.0 0.0 4351260 8 ?? Ss 3:28PM 0:05.95 ssh -Nf -L 18881:my-server:18881
user 3018 0.0 0.0 4334292 52 ?? S 12:08PM 0:00.15 /usr/bin/ssh-agent -l
user 9687 0.0 0.0 4294392 928 s002 S+ 10:48AM 0:00.00 grep ssh
我总是想用 my-server
杀死进程。
有谁知道我怎样才能做到这一点?
最佳答案
for pid in $(ps aux | grep "[m]y-server"| awk '{print $2}');杀-9 $pid;完成
ps 辅助 | grep "[m]y-server"| awk '{print $2}' - 这部分为您提供包含“my-server”的 pids 进程列表。这个脚本将通过这个列表并杀死所有这些进程。
关于linux - 在一行中杀死 'ps aux' 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52975223/