On Monday 14 December 2009 04:57:49 pm Roger P. wrote:
two terminals open
- hack hack hack [start long running process]
- hack hack [type in the name of a command which should be run
immediately after long running process in terminal one finishes–and
somehow it will start immediately afterward].
Definitely offtopic, but there a lot of answers, depending on what you
actually want.
First, are you just talking about running one process after another?
That’s
easy, semicolon, or && if you care about the return value. For example:
pv foo.tar | bzip2 -v9 > foo.tar.bz2 && rm foo.tar
Now, if you do care about them being in separate terminals, you need
some way
to signal the other terminal, and people mentioned various ways to do
that.
Probably the least hacky way might be something like:
mkfifo pipe
tar -cjpSf foo.tar.bz2 foo && echo > pipe
Then, in terminal two:
cat pipe && do_some_other_command
If your problem is that you already started the long-running process,
and now
you want to do something when it’s done, that’s done with wait. Easiest
way,
if the long-running job ignores terminal input, just type the name of
the next
command (and enter) and it’ll probably go to bash. More thorough way, go
to
the terminal where you started it and suspend it with ctrl+Z. Then type
‘bg’
to allow it to continue in the background, and pay attention to the job
number. Then you don’t even need a pid, just wait %n, where n is the job
number.
If you need to safely do this and then trigger something in that other
window,
you can probably figure out how to combine the above into something
useful.
Unfortunately, most of the time I think of things like this, I figure by
the
time I remember all my Unix tricks, the “long-running” job (of maybe a
minute
or two) will be done.