I have a Shell Script that I want to run on Linux.
When I run it manually line by line, it works as desired. But when I put the Code into a File (unbound_update.sh
) and assign proper chmod (chmod +x) permissions, I recieve following error during execution:
unbound_update.sh: 6: [[: not found
Download of unbound_ad_servers list failed!
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3311 100 3311 0 0 11148 0 --:--:-- --:--:-- --:--:-- 11148
unbound_update.sh: 25: [[: not found
Download of unbound root.hints failed!
It seems to me, that Bash does not parse the script correctly.
My Script:
#!/bin/bash
# Updating Unbound resources.
# Place this into e.g. /etc/cron.monthly or /etc/cron.weekly
###[ unbound_ad_servers ]###
curl -sS -L --compressed "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=unbound&showintro=0&mimetype=plaintext" > /etc/unbound/unbound.conf.d/unbound_ad_servers.new
if [[ $? -eq 0 ]]; then
mv /etc/unbound/unbound.conf.d/unbound_ad_servers /etc/unbound/unbound.conf.d/unbound_ad_servers.bak
mv /etc/unbound/unbound.conf.d/unbound_ad_servers.new /etc/unbound/unbound.conf.d/unbound_ad_servers
unbound-checkconf >/dev/null
if [[ $? -eq 0 ]]; then
rm /etc/unbound/unbound.conf.d/unbound_ad_servers.bak
service unbound reload >/dev/null
else
echo "Warning: Errors in unbound configuration due to probably failed update of"
echo "/etc/unbound/unbound.conf.d/unbound_ad_servers:"
unbound-checkconf
mv /etc/unbound/unbound.conf.d/unbound_ad_servers /etc/unbound/unbound.conf.d/unbound_ad_servers.new
mv /etc/unbound/unbound.conf.d/unbound_ad_servers.bak /etc/unbound/unbound.conf.d/unbound_ad_servers
fi
else
echo "Download of unbound_ad_servers list failed!"
fi
###[ root.hints ]###
curl -o /etc/unbound/root.hints.new https://www.internic.net/domain/named.cache
if [[ $? -eq 0 ]]; then
mv /etc/unbound/root.hints /etc/unbound/root.hints.bak
mv /etc/unbound/root.hints.new /etc/unbound/root.hints
unbound-checkconf >/dev/null
if [[ $? -eq 0 ]]; then
rm /etc/unbound/root.hints.bak
service unbound reload >/dev/null
else
echo "Warning: Errors in newly downloaded root.hints file probably due to incomplete download:"
unbound-checkconf
mv /etc/unbound/root.hints /etc/unbound/root.hints.new
mv /etc/unbound/root.hints.bak /etc/unbound/root.hints
fi
else
echo "Download of unbound root.hints failed!"
fi