I need to open a browser and access my server with the ip address 1.2.3.4. First I ping my server and if the ping did not fail I launch the home page in a browser. For this I have written a bash file as follows:
# add ip / hostname separated by white space
myHost=1.2.3.4
# no ping request
COUNT=1
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
# 100% failed
echo "Host : $myHost is down (ping failed) at $(date)"
else
firefox $myHost
fi
But I am getting an error message
Error: no display specified
. Firefox is not launching. What am I doing wrong.
This file is getting called every 5 minutes using a cronjob
. The cronjob
seems to be working fine.