-1

I am trying to schedule a task in /etc/ directory (requires root permission to execute it as a normal user) that open firefox every 2 minutes, in a range of hours using "crontab" and append the occurrence to a file, but for some reason I can't get the firefox to open even though I did it in home/user/file/... but not in /etc/....

the time is recording correctly every two minutes but firefox is not opening up!! I gave the file Lab4 the permission (chmod +x) and my_lab (chmod 777) and that's how I got the file Lab4 to start recording the time.

here is the task :

*/2 4-6 * * * export DISPLAY=:0 && firefox --new-window http://www.google.com | date >> /etc/my_lab/Lab4

here is a pic from my VM enter image description here

  • Is there a specific reason to use FF? ... FF has a very large memory footprint and sometimes may take a while to start. Your use case is unclear... However, if you need to automatically read a webpage every few minutes, you might have better luck with lynx -dump URL for easy formatted text output or for an even smaller footprint curl URL for HTML output. – RubberStamp Sep 18 '18 at 21:48
0

I'm not sure, but it looks like this command:

firefox --new-window http://www.google.com | date >> /etc/my_lab/Lab4

Pipes the "result" of running firefox to date, which doesn't make a lot of sense.

Does it work better like this?

firefox --new-window http://www.google.com && date >> /etc/my_lab/Lab4

Also, another thing to always keep in mind when troubleshooting cron: try the command on the prompt first. Everything after the asterisks is just a command: does it work as expected when you run it yourself? If not, it has nothing to do with cron.

  • You right!!! I just realized that! I fixed it, but still can't open the browser. – Fouzi Medfouni Sep 18 '18 at 19:02
  • If you're running Firefox from cron, please remember that the cron user/daemon will have a different PATH than you do. So, while firefox may start the browser from your user shell, you'll need to specify the full path to run it from a crontab. – Seamus Sep 18 '18 at 23:25
  • Thank you so much I wish I saw this answer before spending 4 consecutive days and nights lol .....I already solved the issue and I used the same solution you're offering lol....But I really appreciate that thought :) – Fouzi Medfouni Sep 19 '18 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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