just a quick question with something I'm not understanding. Everything is working fine - I'm just trying to get my head around something.
I have a very simple Bash script that is restarting dnsmasq once per day:
LogFile="/var/log/logfile"
declare -a CMD_AR=()
declare -a ECHO_OUT=(stopping starting)
STOP=$(service dnsmasq \stop)
SLEEP=$(\sleep 15)
START=$(service dnsmasq \start)
CMD_AR+=($STOP)
CMD_AR+=($START)
z=0
while [[ $z -le 1 ]]; do
DT=`date +%c`
echo "$DT - ${ECHO_OUT[$z]} dnsmasq..." >> ${LogFile}
eval ${CMD_AR[$z]} >> ${LogFile} 2>&1
unset DT
eval ${SLEEP}
z=$[$z+1]
done
So...this works, however, the DT variable never changes. So my log file reads:
Tue 31 Oct 2017 10:57:07 PM MDT - stopping dnmasq
Tue 31 Oct 2017 10:57:07 PM MDT - starting dnmasq
Shouldn't the time string be at least 15 (the value of sleep 15) seconds different? I'm failing to understand why the loop is not re-computing the DT variable - anyone?
Also, I'll take any suggestions on my code as well - I'm a total hack when it comes to scripting.