I am trying to run a BASH script on a Debian machine. The script should run on every startup (so I put the .sh
file in /etc/init.d
) if the mac addr
Slightly modified version:
#!/bin/bash
macfile='/root/.mac.txt'
mac=$(/sbin/ifconfig | grep 'eth0' | tr -s ' ' | cut -d ' ' -f5)
# Shut down if file does not exist
if [ ! -f $macfile ]; then
shutdown -h now
fi
# Verify MAC address against cached value
output=$(cat $macfile)
if [ "$mac" = "$output" ]; then
echo "Server will start"
else
shutdown -h now
fi
Explanation:
[
" and "]
" characters must have a whitespace before and after them$( ... )
syntax instead of backticks