Quote:
Originally Posted by Jajamd
watch -n 180 killall firefox-bin && /usr/bin/firefox
|
This is actually two commands, the first of which reads "every 180 seconds, kill all processes named firefox-bin". The second one, "start /usr/bin/firefox", is only run if the first one exits successfully. Since watch will only exit when you interrupt it (Ctrl+C), you effectively just kill your Firefox every three minutes.
To run two or more commands using
watch, you need to use quotes. For example,
Code:
watch -n 180 'killall firefox-bin && /usr/bin/firefox'
However, you can just use a shell loop instead:
Code:
bash -c 'while [ 1 ]; do killall firefox-bin ; /usr/bin/firefox ; sleep 180 ; done </dev/null &>/dev/null'
watch is a terminal application, this one is a simple shell command; it is better suited for example to the desktop environment startup commands. The redirections at the end hide Firefox error messages from output, in case you run it on the command line.
If you want to make sure Firefox is killed if the script is interrupted or fails, use
Code:
bash -c 'trap "killall -KILL firefox-bin" EXIT ; while [ 1 ]; do killall -TERM firefox-bin ; /usr/bin/firefox ; sleep 180 ; done </dev/null &>/dev/null'
If you intend this to be used in a kiosk-type setup, perhaps a bit more complex script is in order. For example, you could use an inactivity timeout (instead of a fixed period), kill Firefox, and then remove the current profile, restoring a known safe profile, before restarting Firefox. That makes sure that even if the user manages to install a malware toolbar or extension, it is discarded at the next restart.