Mailinglist Archive: opensuse (769 mails)

< Previous Next >
[opensuse] Re: start firefox from script
On Tue, 17 May 2016 02:28, Istvan Gabor <suseuser04@...> wrote:
"Carlos E. R."írta:
On 2016-05-16 21:01, Istvan Gabor wrote:
Hello:

I would like to start firefox browser from bash script. I made this script:

#! /bin/bash

ffpid=`pidof firefox`
ffexit=$?

echo "firefox PID is: $ffpid"

if test $ffexit == 0
then `kill -9 $ffpid`
fi

sleep 5

firefox -P list http://lists.opensuse.org/opensuse/2016-05/all.html &

exit


What I want is to check if firefox is running, if it's runing stop it and start
it again with specific profile with specific URL.
This works with the above script but the problem is if I run the script at
least two times, the second time firefox opens with two tabs,
with the same content in both tabs. How can I force it to open only on tab with
the URL in the command line specified?
In firefox preferences I've set General/Startup: When firefox start: Show a
blank page. I use an old firefox version (24.8.1 ESR,
the last ESR that doesn't have australis uinterface), I don't know if it
matters.

Guessing.

You have to verify that the second time it really obtains the PID of the
running firefox. Then you have to verify that it is killed, and wait
till it does die (not five seconds), and if it doesn't, abort with message.

Suggest kill, then loop till PID is not found. Also suggest do not use
kill 9, but a normal kill.

Thanks Carlos.

I expreminted a little bit with starting and stopping firefox in the command
line.

I start firefox:

firefox

Then I stop it using kill:

ps -e|grep firefox
13404 pts/8 00:00:00 firefox

kill 13404

Then I start it again:

firefox

Now firefox opens the site that was opened before killing firefox (restores
previous session).

If I shutdown firefox from within firefox (close button, or file/quit) and
start it again it opens with blank tab does not restore previous session.

It seems that killing firefox using its pid is not equal to shutting it down.
In the former case it reopens the site which was killed. How could I close
firefox from a script/command line normally as if it would be closed as by a
normal shutdown?

The command "kill" defaults to "SIGTERM" try "SIGHUP".

Either "kill -s <sig-name>" or "kill -n <sig-number"
"kill -<sig-number>" also works, see list via "kill -l"

Shortform: "killall -1 firefox" sends any (with your uid) running
firefox-processes the "SIGHUP" (numeric 1) signal.

- Yamaban.
< Previous Next >
Follow Ups
References