0

I am trying to start FireFox from php script using exec("firefox"). This works fine if i run php file from the terminal but does not work when run by the cron. User for cron & terminal is root. Please suggest some solutions.

vkj
  • 101

2 Answers2

0

You can try using watch. watch -10 <YOUR COMMAND> This will try executing your command every 10 second in terminal.

0

Create a script (and chmod +x it):

#!/bin/bash
export DISPLAY=:0
firefox

Run crontab -e and add at the bottom:

* * * * * /path/to/my/script

..and it'll open Firefox every minute on your user's desktop.


Figured you might also want a feature to automatically close it after some time, instead of incrementing opened windows or tabs. I would suggest creating separate FF profile just for cron. Run firefox -P and create a new profile there. Name it... let's say "cron". Then use this script:

#!/bin/bash
export DISPLAY=:0
firefox -P cron &
sleep 30 # set here any amount of seconds you need
pkill -f "/usr/lib/firefox/firefox -P cron"

Works like charm in my environment.

Oh, you will have to update your everyday links to FF to load your normal profile, for example like this: firefox -P default.

GreggD
  • 1,164
  • 2
  • 11
  • 19