I am trying to use an IF statement to:
- Check if a server is UP
- Check if a file exists on the server
My Code So Far
hostname="somehost.com"
file="somefile.txt"
URL="https://${hostname}/some/directory/${file}"
if [ "ping -c 1 -W 1 ${hostname} 2>/dev/null" ] & [ "wget --spider ${URL} 2>/dev/null" ];
then
echo -e "${hostname} is UP and ${file} is AVAILABLE"
else
echo -e "${hostname} is DOWN or ${file} is UNAVAILABLE"
fi
I have tried testing the IF statement by entering an incorrect hostname and an incorrect file but, the result is incorrect.
Current Output
somehost.com is UP and somefile.txt is AVAILABLE
Expected Output
somehost.com is DOWN and somefile.txt is DOWN