1

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.

Stranger
  • 317

1 Answers1

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).

Anthon
  • 79,293
  • 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 'SO- stop being evil' 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 01 '16 at 06: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 01 '16 at 06:08
  • Well, the content of santehnik.sh is the same as house.sh: export DISPLAY=:0.0 firefox imacros://run/?m=santehnik.iim. And I put that job in the same crontab -e after house.sh like following: 58 * * * * /home/meerim/bin/santehnik.sh. And interesting is that only house.sh is working but the second job is not. – Stranger Jun 01 '16 at 11:29
  • Did you run chmod +x on the new script? – Anthon Jun 01 '16 at 13:00
  • That's where I made a mistake. Thank you very much, @Anthon – Stranger Jun 03 '16 at 11:24