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.
Asked
Active
Viewed 1,527 times
0
2 Answers
0
You can try using watch. watch -10 <YOUR COMMAND>
This will try executing your command every 10 second in terminal.

Sankalp Srivastava
- 101
- 1
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,114
php -f /my/php/file.php
is enough. Just need to have that php-cli installed. – GreggD May 21 '16 at 17:53