我正在编写一个Shell脚本来检查特定服务在远程主机上是否正在运行。如果未运行,它将运行/etc/init.d/afrender start
命令。但不幸的是出现错误
意外令牌'then'附近的语法错误
#!/bin/bash
service='afrender'
for host in $(<workstation.txt);
do
echo "------------------workstation:" $host
sshpass -p 'xxxxx' ssh -o StrictHostKeyChecking=no $host if " [ $((ps ax | grep -v grep | grep $service)) > /dev/null ] "
then
echo "$service is running"
else
/etc/init.d/afrender start
fi
done