I'm trying to write a shell script that ONLY runs if $HOSTNAME is empty (for example on a node that has zeroized). However, even when the host-name has already been set the if condition of my code keeps running. Have I missed something?
$HOSTNAME=$(hostname)
if [ "$HOSTNAME" = "" ]; then
logger "STARTING sleep 120s to complete boot process"
sleep 120
logger "AFTER 120s"
logger "STARTING configuration using script"
/usr/sbin/cli -c '
configure;
#Configuration changes happen here
commit'
else
echo "No changes were made"
fi
HOSTNAME? (Or maybe more relevantly, how are you preventingHOSTNAMEfrom being set, depending on what shell you are using?)HOSTNAME=$(hostname)(no$beforeHOSTNAME, no spaces around the=). If you are usingbash,HOSTNAMEis already set.$prefixed to a parameter name signals a parameter expansion.