这部分代码适用于Ubuntu 16.04,但是当我尝试在CentOS 6.x上运行此代码时,server_url
的值未正确分配,值变为空白。
这是我的代码:
server_url="http://local.host.net"
cat > /etc/cron.daily/update_rules.sh <<EOF
#!/bin/bash
mkdir -p /opt/rules
rm -f /opt/rules/rules.tmp
echo "[`date`] Updating rules ..."
wget $server_url -O /opt/rules/rules.tmp && \
mv /opt/rules/mhn.rules.tmp /opt/rules/mhn.rules && \
(/usr/local/bin/supervisorctl update ; /usr/local/bin/supervisorctl restart appserv ) && \
echo "[`date`] Successfully updated the rules" && \
exit 0
echo "[`date`] Failed to the rules"
exit 1
EOF
我得到了这个结果,请注意第6行:
#!/bin/bash
mkdir -p /opt/rules
rm -f /opt/rules/rules.tmp
echo "[Tue Aug 29 16:42:26 UTC 2017] Updating rules ..."
wget -O /opt/rules/rules.tmp && \
mv /opt/rules/mhn.rules.tmp /opt/rules/mhn.rules && \
(/usr/local/bin/supervisorctl update ; /usr/local/bin/supervisorctl restart appserv ) && \
echo "[`date`] Successfully updated the rules" && \
exit 0
echo "[Tue Aug 29 16:42:26 UTC 2017] Failed to the rules"
exit 1