Linux 命令行使用if语句进行判断
说明: 可以配合ansible进行批量实现
例1: 判断ntp是否启动
systemctl is-active ntpd.service &>/dev/null; if [ $? == 0 ]; then echo "ntp-ok"; else echo "ntp-no" | xargs ;fi
systemctl is-active chronyd.service &>/dev/null; if [ $? == 0 ]; then echo "chronyd-ok"; else echo "chronyd-no" | xargs ;fi
systemctl is-active ntpd.service &>/dev/null; if [ $? == 0 ]; then echo "ntp-ok"; else echo "ntp-no";fi; if systemctl is-active chronyd.service &>/dev/null; then echo "chronyd-ok" | xargs ;fi