Open firefox from bash file "Error: no display specified" [duplicate]

Solution 1:

You have to specify the display.

Add this to your script before running firefox

 export DISPLAY=:0

your script would be like:

#add ip / hostname separated by white space
myHost=1.2.3.4
export DISPLAY=:0
# 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