我想在 Kubernetes pod 中运行一个本地脚本,然后将输出结果设置为一个 linux 变量
这是我尝试过的:
# if I directly run -c "netstat -pnt |grep ssh", I get output assigned to $result:
cat check_tcp_conn.sh
#!/bin/bash
result=$(kubectl exec -ti <pod_name> -- /bin/bash -c "netstat -pnt |grep ssh")
echo "result is $result"
Run Code Online (Sandbox Code Playgroud)
我想要的是这样的:
#script to be called:
cat netstat_tcp_conn.sh
#!/bin/bash
netstat -pnt |grep ssh
#script to call netstat_tcp_conn.sh:
cat check_tcp_conn.sh
#!/bin/bash
result=$(kubectl exec -ti <pod_name> --
/bin/bash -c "./netstat_tcp_conn.sh)
echo "result is $result
Run Code Online (Sandbox Code Playgroud)
结果显示result is /bin/bash: ./netstat_tcp_conn.sh: No such file or directory
。
如何让 Kubernetes pod 执行我本地机器上的 netstat_tcp_conn.sh?
您可以使用以下命令在 pod 中执行脚本:
kubectl exec POD -- /bin/sh -c "`cat netstat_tcp_conn.sh`"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
512 次 |
最近记录: |