Open firefox from bash file "Error: no display specified"

Pre

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.

Maythux

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

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Selenium Firefox Driver reading from Hosts file

分類Dev

Open file from zip without extracting it in Python?

分類Dev

How to get value of variable from open file

分類Dev

Can not open PDF file from using WebView

分類Dev

Open csv file from folder created in application

分類Dev

how to open an exe file from google chrome

分類Dev

Open file from terminal in specific application

分類Dev

GNU Screen: Open window and send command from loop in Bash script

分類Dev

Extract values from a property file using bash

分類Dev

Removing strings from file using bash script

分類Dev

How to concatenate a string from an included file in bash

分類Dev

How to pass input to a command from file in Bash

分類Dev

funky file name output from shell/bash?

分類Dev

Create new file with spaces from argument BASH

分類Dev

Bash sed delete line from file not working

分類Dev

read a file from Server path - bash

分類Dev

How can I avoid Firefox's "you have chosen to open" dialog when I try to download a file?

分類Dev

Run bash script from curl failed while from file succeeded

分類Dev

Shortcut key to open a downloaded file from the download bar in chrome (for selenium)

分類Dev

C# open and edit .xls file right from stream

分類Dev

Cannot open the output file generated from running an exe

分類Dev

Open silent excel file from list to change value to specific cell

分類Dev

"Unable to open file for reading" attaching PDF from storage to mailable

分類Dev

How do I open .cpp file from the github directory?

分類Dev

How can I "open" a file from WSL with the default application?

分類Dev

'UnknownError' on indexedDB.open in Firefox

分類Dev

bat file to issue a git pull command and leave the git bash window open

分類Dev

bash: how to source array from section config file after sed?

分類Dev

Extracting value from ipmitool text file using bash

Related 関連記事

  1. 1

    Selenium Firefox Driver reading from Hosts file

  2. 2

    Open file from zip without extracting it in Python?

  3. 3

    How to get value of variable from open file

  4. 4

    Can not open PDF file from using WebView

  5. 5

    Open csv file from folder created in application

  6. 6

    how to open an exe file from google chrome

  7. 7

    Open file from terminal in specific application

  8. 8

    GNU Screen: Open window and send command from loop in Bash script

  9. 9

    Extract values from a property file using bash

  10. 10

    Removing strings from file using bash script

  11. 11

    How to concatenate a string from an included file in bash

  12. 12

    How to pass input to a command from file in Bash

  13. 13

    funky file name output from shell/bash?

  14. 14

    Create new file with spaces from argument BASH

  15. 15

    Bash sed delete line from file not working

  16. 16

    read a file from Server path - bash

  17. 17

    How can I avoid Firefox's "you have chosen to open" dialog when I try to download a file?

  18. 18

    Run bash script from curl failed while from file succeeded

  19. 19

    Shortcut key to open a downloaded file from the download bar in chrome (for selenium)

  20. 20

    C# open and edit .xls file right from stream

  21. 21

    Cannot open the output file generated from running an exe

  22. 22

    Open silent excel file from list to change value to specific cell

  23. 23

    "Unable to open file for reading" attaching PDF from storage to mailable

  24. 24

    How do I open .cpp file from the github directory?

  25. 25

    How can I "open" a file from WSL with the default application?

  26. 26

    'UnknownError' on indexedDB.open in Firefox

  27. 27

    bat file to issue a git pull command and leave the git bash window open

  28. 28

    bash: how to source array from section config file after sed?

  29. 29

    Extracting value from ipmitool text file using bash

ホットタグ

アーカイブ