Unix administration - Execute all processes in the background from bash.

This is Interesting: Free IT Magazines  
Home > Archive > Unix administration > May 2004 > Execute all processes in the background from bash.





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Execute all processes in the background from bash.
guerrilla_thought

2004-05-19, 5:38 am

I was wondering if it's possible to prepend "time" and append "&" to all
commands that I execute in bash. For example I'd like
$ mozilla
to exapand to
$ time mozilla &
to time it and execute it in the background. Anyone know if this is
possible using bash, maybe with environment variables? It's quite
inconvenient to type time before and & after every command that I execute.
Thank you.

* Anthony
Alan Connor

2004-05-19, 5:38 am

On Wed, 19 May 2004 08:33:06 GMT, guerrilla_thought <guerrilla_thought@gmx.de> wrote:
>
>
> I was wondering if it's possible to prepend "time" and append "&" to all
> commands that I execute in bash. For example I'd like
> $ mozilla
> to exapand to
> $ time mozilla &
> to time it and execute it in the background. Anyone know if this is
> possible using bash, maybe with environment variables? It's quite
> inconvenient to type time before and & after every command that I execute.
> Thank you.
>
> * Anthony


One way would be to use the PROMPT_COMMAND Bash variable to run a function
just before the prompt came up:

function_name () {

read PC

time "${PC}" &

}

Doesn't really run in the background, though, and I can't make common
commands run in the background at all. Try ls & ...

Of course, that function takes away your prompt, so you need to
include one in the function...

Hang around. There are probably better ideas coming along...


AC

--
Pass-List -----> Block-List ----> Challenge-Response
The key to taking control of your mailbox. Design Parameters:
http://tinyurl.com/2t5kp || http://tinyurl.com/3c3ag
Challenge-Response links -- http://tinyurl.com/yrfjb
Timo Felbinger

2004-05-19, 5:40 pm


On Wed, 19 May 2004, guerrilla_thought wrote:

> I was wondering if it's possible to prepend "time" and append "&" to all
> commands that I execute in bash. For example I'd like
> $ mozilla
> to exapand to
> $ time mozilla &
> to time it and execute it in the background. Anyone know if this is
> possible using bash, maybe with environment variables? It's quite
> inconvenient to type time before and & after every command that I execute.
> Thank you.
>


If your bash is using GNU-readline for obtaining user input (it probably
does), then you could add something similar to the following into your
~/.inputrc:

'\C-a': beginning-of-line
'\C-e': end-of-line
'\C-n': accept-line
'\C-m': "\C-a time \C-e &\C-n"

See the readline man page for more details.


Regards,

Timo Felbinger


--
Timo Felbinger <Timo.Felbinger@physik.uni-potsdam.de>
Quantum Physics Group http://www.quantum.physik.uni-potsdam.de
Institut fuer Physik Tel: +49 331 977 1793 Fax: -1767
Universitaet Potsdam, Germany
Doug Freyburger

2004-05-19, 5:40 pm

guerrilla_thought wrote:
>
> I was wondering if it's possible to prepend "time" and append "&" to all
> commands that I execute in bash. For example I'd like
> $ mozilla
> to exapand to
> $ time mozilla &
> to time it and execute it in the background. Anyone know if this is
> possible using bash, maybe with environment variables? It's quite
> inconvenient to type time before and & after every command that I execute.


All/every? I use ls, cd and so on often enough that would be a
disaster for me.

When I intend to run a command very often, I write a small script
and name it "x" somewhere in my path. It would be something like:

#! /bin/bash
time ${1} &
exit

Then I would type most of my commands normally and "x mozilla".
Since you mentioned mozilla, you probably want to use "nohup" rather
than "time".
Ed Morton

2004-05-19, 5:40 pm



Doug Freyburger wrote:

<snip>
> All/every? I use ls, cd and so on often enough that would be a
> disaster for me.
>
> When I intend to run a command very often, I write a small script
> and name it "x" somewhere in my path. It would be something like:
>
> #! /bin/bash
> time ${1} &


You might want to make the above:

time "$@" &

so you capture arguments.

> exit


No need for the exit.

Ed.
>
> Then I would type most of my commands normally and "x mozilla".
> Since you mentioned mozilla, you probably want to use "nohup" rather
> than "time".


Doug Freyburger

2004-05-20, 5:37 pm

Ed Morton wrote:
> Doug Freyburger wrote:
>
>
>
> You might want to make the above:
> time "$@" &
> so you capture arguments.


Good point.

>
> No need for the exit.


True but there isn't necessarily need for the magic number in the first
line, either. I put them into all of my scripts for cleanliness reasons.
Kevin Collins

2004-05-20, 5:37 pm

In article <7960d3ee.0405200757.2b49b50f@posting.google.com>, Doug Freyburger
wrote:
> Ed Morton wrote:
>
> Good point.
>
>
> True but there isn't necessarily need for the magic number in the first
> line, either. I put them into all of my scripts for cleanliness reasons.


I assume you mean the "shebang" entry (#!/bin/bash)? If so, there is a need for
it, unless you want all your scripts to run as /bin/sh, which you probably
don't.

Kevin
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com