我正在编写一个登录到远程节点的bash脚本,并返回在该节点上运行的服务。
#!/bin/bash
declare -a SERVICES=('redis-server' 'kube-controller-manager' 'kubelet' 'postgres' 'mongod' 'elasticsearch');
for svc in "${SERVICES[@]}"
do
RESULT=`ssh 172.29.219.109 "ps -ef | grep -v grep | grep $svc"`
if [ -z ${RESULT} ]
then
echo "Is Empty" > /dev/null
else
echo "$svc is running on this node"
fi
done
现在节点上ssh 172.29.219.109 "ps -ef | grep -v grep | grep $svc"
的输出是::
postgres 2102 1 0 Jan29 ? 00:24:27 /opt/PostgresPlus/pgbouncer/bin/pgbouncer -d /opt/PostgresPlus/pgbouncer/share/pgbouncer.ini
postgres 2394 1 0 Jan29 ? 00:20:10 /opt/PostgresPlus/9.4AS/bin/edb-postgres -D /opt/PostgresPlus/9.4AS/data
postgres 2431 2394 0 Jan29 ? 00:00:01 postgres: logger process
postgres 2434 2394 0 Jan29 ? 00:07:15 postgres: checkpointer process
postgres 2435 2394 0 Jan29 ? 00:01:10 postgres: writer process
postgres 2436 2394 0 Jan29 ? 00:03:27 postgres: wal writer process
postgres 2437 2394 0 Jan29 ? 00:20:03 postgres: autovacuum launcher process
postgres 2438 2394 0 Jan29 ? 00:37:00 postgres: stats collector process
postgres 2494 1 0 Jan29 ? 00:08:12 /opt/PostgresPlus/9.4AS/bin/pgagent -l 1 -s /var/log/ppas-agent-9.4.log hostaddr=localhost port=5432 dbname=postgres user=postgres
postgres 2495 2394 0 Jan29 ? 00:11:25 postgres: postgres postgres 127.0.0.1[59246] idle
当我运行脚本时,我确实得到了我想要的结果但是我收到了一条不需要的消息,这些消息似乎与我存储结果的变量有关。
# ./map_services_to_nodes.sh
./map_services_to_nodes.sh: line 12: [: too many arguments
postgres is found on this node
我使用的Algo是::
答案 0 :(得分:0)
在使用$
命令时,你需要转义"
(以避免本地扩展)和ssh
,同时避免使用过时的反向命令进行命令替换,使用{{ 1}},请参阅Why Use $(STATEMENT) instead of legacy STATEMENT
$(..)
和RESULT=$(ssh 172.29.219.109 "ps -ef | grep -v grep | grep \$svc")
运算符中的双引号变量
test
答案 1 :(得分:0)
更改了以下内容
var r = confirm("Submit the form?");
if (r==true) {
('#cat_add').on('submit', function(e) {
$.post("Process.php", $(this).serialize());
});
}
到
if [ -z ${RESULT} ]
并且有效。
if [ -z "${RESULT}" ]