我需要在命令中尝试grep ecm模拟器的PID并使用kubectl杀死它的命令提供帮助:
kubectl exec eric-service-0 -n cicd --kubeconfig /root/admin.conf -- bash -c "ps -ef | grep ecm | grep node | awk '{print $2}' "
以上命令的输出:
root 9857 0 0 07:11 ? 00:00:00 bash -c /tmp/simulator/node-v8.11.3-linux-x64/bin/node /tmp/simulator/ecm_mod.js> /tmp/simulatorEcmResponse.txt
root 9863 9857 0 07:11 ? 00:00:00 /tmp/simulator/node-v8.11.3-linux-x64/bin/node /tmp/simulator/ecm_mod.js
预期输出是:
9857
9863
然后我还需要杀死PID:
kubectl exec eric-service-0 -n cicd --kubeconfig /root/admin.conf -- bash -c "ps -ef | grep ecm | grep node | awk '{print $2}' | xargs kill -9"
当我在服务舱中执行相同操作时,它正在工作,但是当我从外面通过kubectl执行操作时,它会出现问题。
有人可以让我知道我在做什么错吗?
注意:需要从以下输出中删除2个PID:
eric-service-0:/ # ps -ef | grep ecm | grep node
root 9857 0 0 07:11 ? 00:00:00 bash -c /tmp/simulator/node-v8.11.3-linux-x64/bin/node /tmp/simulator/ecm_mod.js> /tmp/simulatorEcmResponse.txt
root 9863 9857 0 07:11 ? 00:00:00 /tmp/simulator/node-v8.11.3-linux-x64/bin/node /tmp/simulator/ecm_mod.js
编辑:
如下@Cyrus要求的命令输出:
将此发布为Community Wiki以获得更好的可见性。 @Cyrus在评论中提供了解决方案。
简而言之,OP希望使用其PID's
终止/中断某些进程。 OP希望从包含ecm simulator
的特定吊舱/容器的群集级别开始。
为此,使用了以下命令:
- [
exec
-在容器中执行命令-- bash
-在容器中运行bash- [
ps -ef
-列出系统上的所有进程- [
grep
-特定于搜索的模式- [
awk
-模式扫描和处理语言。xargs
-从标准输入生成并执行命令行- [
kill
-向进程发送信号在
MANUAL
中,您可以找到有关ps
标志的一些信息:
To see every process on the system using standard syntax: ps -e ps -ef ps -eF ps -ely
但是每个标志仍将给出另一个输出,如下所示:
-e PID TTY TIME CMD -ef UID PID PPID C STIME TTY TIME CMD
Cyrus建议使用以下命令:
kubectl exec eric-service-0 -n cicd --kubeconfig /root/admin.conf -- bash -c "pgrep -f 'node.*ecm'"
[
bash -c
-如果存在-c选项,则从第一个非选项参数command_string中读取命令。
也请在评论中解释:
pgrep查看当前正在运行的进程,并列出与选择标准匹配的进程ID。来自人pgrep。 node。* ecm是regex。