You are not logged in.

#1 2010-12-25 12:26:20

sekereg3
Member
Registered: 2010-12-09
Posts: 6

[solved] bash: restarting firefox from script in cron

Hi, I wrote a script that updates firefox-nightly, inside the script I am having problems restarting firefox-nightly after the update. It does restart properly when run from inside a X session, but not from dcron. Any advice?

restart function:

restartff() {                                                                   
    kill $(pgrep firefox) && firefox-nightly --display=:0                                    
}

crontab:

00 03 * * * bash /usr/local/bin/firefox-nightly-update

Last edited by sekereg3 (2010-12-25 16:53:51)

Offline

#2 2010-12-25 14:03:55

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [solved] bash: restarting firefox from script in cron

Doesn't cron run as root? Running GUI apps as root is not a good thing + you need to properly set up your system to do that.

Offline

#3 2010-12-25 14:07:06

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,598
Website

Re: [solved] bash: restarting firefox from script in cron

@karol - deps.  If the op put that line in his user's crontab it'll run as his user.  If he has it in root's crontab or in the /etc/cron.d folders then you're right it'll run as root.  In that scenario, start the script with a su user -c like this:

00 03 * * * su USERNAME -c /usr/local/bin/firefox-nightly-update

CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#4 2010-12-25 15:13:48

sekereg3
Member
Registered: 2010-12-09
Posts: 6

Re: [solved] bash: restarting firefox from script in cron

yes, of course I have it in my users crontab.

Offline

#5 2010-12-25 15:43:23

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,598
Website

Re: [solved] bash: restarting firefox from script in cron

sekereg3 wrote:

yes, of course I have it in my users crontab.

...I assumed that you did.  Just wanted to follow-up on k's post.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#6 2010-12-25 15:44:51

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [solved] bash: restarting firefox from script in cron

sekereg3 wrote:

yes, of course I have it in my users crontab.

Ooops, sorry then.
Firefox is an X application so I think it needs an X display to connect to.

You can give 'nohup' a shot:

restartff() { kill $(pgrep firefox) && nohup firefox-nightly --display=:0 & }

Last edited by karol (2010-12-25 16:01:19)

Offline

#7 2010-12-25 16:22:44

hellomynameisphil
Member
From: /home/phil/Vancouver
Registered: 2009-10-02
Posts: 257
Website

Re: [solved] bash: restarting firefox from script in cron

you can also add the line

DISPLAY=:0.0

or whatever directly to your crontab before your jobs. Then you only have to specify the display once for any X apps you run via cron, assuming you want to have them all run on the same display.

EDIT: No, I am wrong about exporting. I can't get it to work as advertised. But I can put something like this in my crontab and run X apps via cron:

* * * * * DISPLAY=:0.0 /usr/bin/my-gui-cron-job

However, it looks like you have to specify the display with every job in the list for every X app you want to run via cron. I have tried exporting it both at the beginning of the crontab file and on the job line itself, but I am unable to specify the display just once for multiple gui cron jobs. Still, the above is handy for a graphical app which has no command-line switch to specify a display and which is to be run by cron.

Anyway, I know the OP's problem is solved, but I want to make sure no one else bangs their head against the wall due to my misinformation.

Last edited by hellomynameisphil (2010-12-26 06:12:27)

Offline

#8 2010-12-25 16:41:12

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [solved] bash: restarting firefox from script in cron

hellomynameisphil wrote:

you can also add the line

DISPLAY=:0.0

or whatever directly to your crontab before your jobs. Then you only have to specify the display once for any X apps you run via cron, assuming you want to have them all run on the same display.

I think it should be 'export DISPLAY=:0.0'.

Offline

#9 2010-12-25 16:51:11

sekereg3
Member
Registered: 2010-12-09
Posts: 6

Re: [solved] bash: restarting firefox from script in cron

Thanks for the help everyone, karol's suggestion works perfectly. hellomynameisphil: very nice suggestion for future scripts/ideas.

Offline

Board footer

Powered by FluxBB