linux - 在一行中杀死“ps aux”输出
问题描述
我必须每天多次做同样的事情:
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}'); do kill -9 $pid; done
ps辅助| grep "[m]y 服务器" | awk '{print $2}' - 这部分为您提供包含“my-server”的 pids 进程列表。这个脚本将遍历这个列表并杀死所有这些进程。
推荐阅读
- vba - VBA宏来计算分钟
- asp.net-mvc - 这些声明类型/Xml 网址是什么?架构?
- aws-lambda - AWS 无服务器 Java Lambda 调试
- c - 当堆被写入时,top(活动监视器)如何更新内存使用情况?(C)
- javascript - 事件监听器问题
- javascript - 将元素附加到 HTML 时看不到子元素
- sql - 使用从旧表开始的一些列创建新表
- javascript - 客户端速度测试
- c# - EF Core 有条件地启用延迟加载
- javascript - Google Docs - programmatically send mouse click to an item in outline pane