Occasionally I fire up pine in a shell window when I have a pine process
running already; such things happen. The moment I do this, in my current
set-up, the new pine process attempts to take charge and disable
the old one as much as possible---it wants the old one to become
read-only etc etc, which is sensible because I shouldn't think you
want pines writing to one mail folder.
But sometimes this fails, or at least has unfortunate side-effects---e.g. if
I have suspended a pine process then start a second one, then the
second one might spend a long time trying to get a response from
the first, during which the second process is unresponsive etc etc.
Not much fun.
Over the years I have come to realise that 99.9 percent of the
time, when I fire up a second pine process with one running already,
it is an oversight on my part, rather than a carefully-planned idea.
So I'd like to change the default! When I fire up a second pine process,
I don't want it to try and wrest control of my mailbox folders from
the first one, I want it to start up crippled---i.e. the *second*
process should be read-only---or perhaps not even start up at all!
("There is already a pine process running: sort yourself out buster
and then get back to me coz I ain't starting another one unless you beg"
sort of thing).
Is this easy to do?
buzzard
> So I'd like to change the default! When I fire up a second pine process,
> I don't want it to try and wrest control of my mailbox folders from
> the first one, I want it to start up crippled---i.e. the *second*
> process should be read-only---or perhaps not even start up at all!
> ("There is already a pine process running: sort yourself out buster
> and then get back to me coz I ain't starting another one unless you beg"
> sort of thing).
For that second way, you may use this small shell script:
ps -u yourloginhere | grep pine -q || pine
which will start pine if there's not another one, or do nothing. If you do
want some error message then, get back to me.
--
LL
> For that second way, you may use this small shell script:
> ps -u yourloginhere | grep pine -q || pine
> which will start pine if there's not another one, or do nothing. If you do
> want some error message then, get back to me.
Would that work? Wouldn't the grep command itself appear with pine
causing the program not to run? I would try this...
ps -u login | grep -v grep | grep pine -q || pine
I haven't tested the above line.
John
--
John Mayson <jo...@mayson.us>
Austin, Texas, USA
> Would that work?
I tried it and it did, but I don't quite understand why.
ps auxww | grep pine
finds "grep pine"
but
ps -u buzzard | grep pine
doesn't. It might be a race condition though, i.e. it might occasionally
not work.
> I would try this...
>
> ps -u login | grep -v grep | grep pine -q || pine
Another problem with both suggestions is that now "pine user@hostname"
doesn't do what you want it to do; this can be fixed with a careful $@.
I asked the question here because I was expecting a "pine" solution.
I got a "unix" solution instead, but that's good enough for me. In
fact I just wrote my own shell script, which has held up so far:
$ cat ~/bin/pine
if (ps -u buzzard | grep pine -q) then
echo "pine already running?"
ps auxww | grep pine | grep -v grep;
else
pine $@;
fi
$
Note that I use grep -v once but not twice, indicating that I don't
really understand what's going on :-)
buzzard
> John Mayson <jo...@mayson.us> wrote:
>
> > Would that work?
>
> I tried it and it did, but I don't quite understand why.
>
> ps auxww | grep pine
>
> finds "grep pine"
>
> but
>
> ps -u buzzard | grep pine
>
> doesn't. It might be a race condition though, i.e. it might occasionally
> not work.
Your remark made me wonder also, because occasionally when I grep to find
process foo I get that "grep foo" line. Looking at the man gives the
answer: ps -u username displays only process names, not full command line.
Thus, not the arguments of grep:
coulomb:~> ps -u lucas |grep pine
4471 pts/0 00:00:02 pine
coulomb:~> ps -fu lucas |grep pine
lucas 4445 1 0 09:27 ? 00:00:06 gnome-terminal --window-with-profile=mail --geometry=82x24-0-0 -x pine -i -passfile /home/lucas/pine/passfile
lucas 4471 4445 0 09:27 pts/0 00:00:02 pine -i -passfile /home/lucas/pine/passfile
lucas 11588 4485 0 12:08 pts/2 00:00:00 grep pine
More fun:
coulomb:~> ps -u lucas |grep grep
11641 pts/2 00:00:00 grep
coulomb:~> ps -fu lucas |grep grep
lucas 11843 4485 0 12:14 pts/2 00:00:00 grep grep
;-)
--
LL
> Would that work? Wouldn't the grep command itself appear with pine
> causing the program not to run? I would try this...
>
> ps -u login | grep -v grep | grep pine -q || pine
>
> I haven't tested the above line.
Good lord! The followups on this are scary, too.
I'm pretty sure that Linux has pgrep now, and if it runs anything like
Solaris,
pgrep -u $USER pine || pine
or, crank it along the lines of
pgrep -u $USER pine && echo "Pine already running." || pine
--
Andre van Eyssen.
mail: an...@purplecow.org jabber: an...@interact.purplecow.org
purplecow.org: UNIX for the masses http://www2.purplecow.org
purplecow.org: PCOWpix http://pix.purplecow.org