1

This question already has an answer here:

I have the shell script which opens Firefox and launches macros in it (I use a Firefox add-on called Imacros to create macros). The content of my shell script named house.sh is like that:

firefox imacros://run/?m=house.iim

And I created a scheduled job via crontab -e to run that script hourly every day:

47 * * * * /home/meerim/bin/house.sh

But nothing happened (Firefox didn't open). Then I tried this:

47 * * * * env DISPLAY=:0.0 /home/meerim/bin/house.sh

But it didn't solve the problem.
So how should I fix it?
My house.sh script works properly when I run it from terminal.

marked as duplicate by Gilles, Jeff Schaller, taliezin, Archemar, X Tian Jun 1 '16 at 9:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

You should be able to get this to run by putting in house.sh:

export DISPLAY=:0.0

and running xhost + on your interface. Once that works you can restrict who is allowed to connect (using xhost again), but once things stop working you'll know how permissive you have to be.

This will not work if you are not logged in. I there run firefox from a python script started with crontab, and the actual interface opens in a Xvnc screen independent of whether I am logged in or not (and it doesn't clobber my UI once it starts running).

  • I've added export DiSPLAY=:0.0 to house.sh and it worked! And now I'm trying to fulfill ur second recommendation about xhost. I ran xhost + and it said that clients can connect from any host. Now I should restrict allowance but how I will do it, I mean I should put my username or the value that I get from running hostname command in the code: xhost - name. By the way, I use Ubuntu desktop. – Stranger May 31 '16 at 13:48
  • If it already works, you don't need to use xhost + at all, that was to make sure you could connect and were not restricted by X. After logging out and back in this will reset to normal values (or run xhost -) – Anthon May 31 '16 at 15:22
  • This is the 21st century. I cannot condone a recommendation to run xhost +. – Gilles May 31 '16 at 21:23
  • I added a new job to my crontab exactly the same as previous one like that 58 * * * * /home/meerim/bin/santehnik.sh. But it doesn't work. Only the first one which is house.sh. Although I put in santehnik.sh "export DISPLAY=:0.0" too. What's wrong with it? – Stranger Jun 1 '16 at 6:05
  • @Stranger difficult to tell without seeing the scripts. Did you put it at the beginning? Are you calling Firefox again? Maybe better to put up a new question showing both scripts. – Anthon Jun 1 '16 at 6:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.