我正在尝试让它运行,但运气不佳。我想看看是否存在 2 项服务。如果它们存在并且被禁用,则应该返回通过。如果没有则失败。
#!/bin/bash
# echo "Reference Number~Result~Risk Rating~Service~Service Status~Startup Mode~Other Information~Last Results time"
z=$[svcs -a | grep comsat]
y=$[svcs -a | grep comsat-udp]
if [ "$z" = "online"* ] && [ "$y" = "online"* ]
then
echo "SET-4555~Pass~High~~~~"
else
echo "SET-4555~Fail~High~~~$z~"
fi
答案1
您的代码中有一些错误:
#!/bin/bash
# echo "Reference Number~Result~Risk Rating~Service~Service Status~Startup Mode~Other Information~Last Results time"
z=$(svcs -a | grep comsat)
y=$(svcs -a | grep comsat-udp)
if [ "$z" == "XXX" ] && [ "$y" == "XXX" ]
then
echo "SET-4555~Pass~High~~~~"
else
echo "SET-4555~Fail~High~~~$z~"
fi
其中XXX
表示变量的输出z
,y