[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash: finding if mozilla is running



On Sat, 2003-07-26 at 19:22, David selby wrote:
> Hello,
> 
> Writting a small script to make mozilla show the results of HTML code 
> written in vi, when vi saves, the script  automaticly changes mozilla to 
> show that HTML.
> 
> I need to know if mozilla is running, if not I need to call it first ... 
> seemed simple
> 
> if ! ps ax | grep "mozilla-bin" &>/dev/null; then
>         /usr/local/mozilla/mozilla -P web &
>         .....
> 
> This worked the first time then I get
> 
> web@debian:/usr/local/myfiles/dave/debian/sh files$ ./HTMLgui
>  7508 pts/0    S      0:00 grep mozilla-bin
> 
> Ie its picking up on the grep process, finding "mozilla-bin", saying yep 
> its running, dont call mozilla & bang, script fails.
> 
> Whatever I grep for, grep will find in ps ax as grep xxxxxx, a bit 
> frustrating !!

grep -v grep will ensure that the grep line is removed. eg

	if ! ps ax | grep "mozilla-bin" | grep -v grep ...

rgh

> 
> Help
> Dave
> 
> PS still a newbe BASH scripter, If there is a better way of doing this, 
> let me know.
> 
> 
> #!/bin/sh
> 
> # HTMLgui ... enable Mozilla to provide a GUI for vi
> 
> currentdir=/usr/local/myfiles/dave/websites/current
> oldhtml="mismatch"
> 
> 
> if ! ps ax | grep "mozilla-bin"; then
>         /usr/local/mozilla/mozilla -P web &
>         sleep 3s
> fi
> 
> echo
> while true; do
> html=$(ls -t1 $currentdir/*.html | head -n 1)
> if [ $oldhtml = $html ]; then
>         sleep 1s
> else
>         echo -e "HTMLgui ... changing to ${html##/*/}"
>         oldhtml=$html
>         /usr/local/mozilla/mozilla -P web -remote "openFile($html)"
> fi
> done
-- 
"It is possible to make things of great complexity out of things
 that are very simple. There is no conservation of simplicity"
 -- Stephen Wolfram

Richard Heycock <rgh@roughage.com.au>
tel : 0410 646 369
key fingerprint : 909D CBFA C669 AC2F A937 AFA4 661B 9D21 EAAB 4291



Reply to: