In bash I want to test if there is a DNS entry for a hostname. If there is then I want to do X otherwise do Y.
How can I write this? So far I am thinking the following:
if [[ `ping -c 1 $1 2> /dev/null` ]]; then
# the hostname was not found
# perform Y
else
# the hostname was found
# perform X
fi;
After writing this I am not certain of whether to use &2> instead of 2>. With different exit codes it might be better for me to just do X when the exit code of the ping command is 0.
How would I put this?