How to spawn another shell script in separate process
Hi, I have a shell script A which runs as non-root. From this script (A) I am need to launch script B which must run as root, while continuing running script A without waiting script B to finish (in other words, I am need to spawn script B from script A in separate process). Anuone can suggest me how to do it? Thanks in advance for any suggestion. ********************************************* * Best Regards --- Andrei Verovski * * Personal Home Page * http://snow.prohosting.com/guru4mac * Mac, Linux, DTP, Development, IT WEB Site *********************************************
On Thu, Sep 18, 2003 at 12:05:28PM +0300, andreil1@mail.starlett.lv wrote:
Hi,
I have a shell script A which runs as non-root. From this script (A) I am need to launch script B which must run as root, while continuing running script A without waiting script B to finish (in other words, I am need to spawn script B from script A in separate process).
Anuone can suggest me how to do it?
Adding an ampersand (&) at the end of a command launches it as another process. You should probably use 'sudo' to give it root privileges. HTH... -- David Smith Work Email: Dave.Smith@st.com STMicroelectronics Home Email: David.Smith@ds-electronics.co.uk Bristol, England GPG Key: 0xF13192F2
The 03.09.18 at 10:28, Dave Smith wrote:
(in other words, I am need to spawn script B from script A in separate process).
Adding an ampersand (&) at the end of a command launches it as another process. You should probably use 'sudo' to give it root privileges.
However, the parent script doesn't exit till the child exits. -- Cheers, Carlos Robinson
On Fri, Oct 17, 2003 at 12:00:33AM +0200, Carlos E. R. wrote:
The 03.09.18 at 10:28, Dave Smith wrote:
(in other words, I am need to spawn script B from script A in separate process).
Adding an ampersand (&) at the end of a command launches it as another process. You should probably use 'sudo' to give it root privileges.
However, the parent script doesn't exit till the child exits.
Wrong. Here is an example. File a.sh: #!/bin/bash echo running sleep in background... sleep 10 & Now run a.sh: kastus@kastus:~> date ; ./a.sh ; date Thu Oct 16 17:52:36 PDT 2003 running sleep in background... Thu Oct 16 17:52:36 PDT 2003 kastus@kastus:~> date Thu Oct 16 17:52:38 PDT 2003 kastus@kastus:~> So parent script does not wait for the child to exit. Regards, -Kastus
The 03.10.16 at 17:54, Kastus wrote:
However, the parent script doesn't exit till the child exits.
Wrong.
No, I'm not. I run an ip-up.local script calling another script (with &): /etc/ppp/ip-up.local.doit & and it doesn't _exit_ till the child exits. I tried hard, some years ago. As a hack - I was tired of trying many combinations - I'm doing it as: at -f /etc/ppp/ip-up.local.doit now and it works.
Here is an example. [...] So parent script does not wait for the child to exit.
That doesn't prove my point. The first script executes completely, yes. But it doesn't _exit_ till the child exits! Mind the word: "exit". Not finishing execution, but exiting completely, freeing the ID, not showing as running process. Parent processes usually wait for children to complete before exiting themselves, or at least, scripts do. -- Cheers, Carlos Robinson
On Fri, Oct 17, 2003 at 02:09:53PM +0200, Carlos E. R. wrote:
The 03.10.16 at 17:54, Kastus wrote:
However, the parent script doesn't exit till the child exits.
Wrong.
No, I'm not. I run an ip-up.local script calling another script (with &):
/etc/ppp/ip-up.local.doit &
and it doesn't _exit_ till the child exits. I tried hard, some years ago. As a hack - I was tired of trying many combinations - I'm doing it as:
at -f /etc/ppp/ip-up.local.doit now
and it works.
I would advise to look into your ip-up.local.doit script, there might be something wrong inside it.
Here is an example. [...] So parent script does not wait for the child to exit.
That doesn't prove my point. The first script executes completely, yes. But it doesn't _exit_ till the child exits!
Mind the word: "exit". Not finishing execution, but exiting completely, freeing the ID, not showing as running process. Parent processes usually wait for children to complete before exiting themselves, or at least, scripts do.
Parent process DOES exit. Please try yourself the following example: a.sh: -------------------------------- #!/bin/bash date echo in a.sh before calling b.sh echo a.sh runs as PID $$ ./b.sh & date echo b.sh started in background ------------------------------- b.sh: ------------------------------ #!/bin/bash echo running sleep... sleep 20 echo back from sleep ----------------------------- kastus@kastus:~> ./a.sh Fri Oct 17 12:21:48 PDT 2003 in a.sh before calling b.sh a.sh runs as PID 6732 Fri Oct 17 12:21:48 PDT 2003 b.sh started in background kastus@kastus:~> running sleep... kastus@kastus:~> ps x |grep 6732 6742 pts/5 S 0:00 grep 6732 kastus@kastus:~> back from sleep kastus@kastus:~> As you see, there is no process running a.sh while b.sh is running in background. If you need help with your /etc/ppp/ip-up.local.doit script, I would be more than happy to help. To contact me privatly substitute NOSPAM with kastus in my address. Regards, -Kastus
I think you guys are looking for "wait". my_prog & wait # Don't run the rest of the script until 'my_prog' finished. -- Micxz
The 03.10.17 at 12:26, Kastus wrote:
/etc/ppp/ip-up.local.doit &
I would advise to look into your ip-up.local.doit script, there might be something wrong inside it.
I did, I did... I had a line: /etc/ppp/ip-up.local.doit & Just that, nothing strange. No wait command. And till the child exited, the pppd daemon did not say that ip-up had finished. Strange, yes... but unless it thought ip-up had finished, it refused to call ip-down. Maybe it has something to do with not having a terminal asociated, or that it is started from a daemon?
Parent process DOES exit. Please try yourself the following example:
I tried, and I agree, your sample works. But the same idea in ip-up.local, did not. I might try again, but I'm reluctant to do so, as it is working in my twisted ways ;-) Ok, I try - offline. 14769 pts/13 S 0:00 /bin/bash /etc/ppp/ip-up.local.doit now 14773 pts/13 S 0:00 \_ /bin/bash /etc/ppp/ip-up.local.doit now 14779 pts/13 S 0:00 \_ /usr/bin/fetchmail -v -L /var/log/fm.log You seem to be right, not ip-up nor ip-up.local show as processes there. However... I'm sure that if I try on line via the ppp daemon, "he" will insist the script has not finished (a wait command, perhaps?). I'm curious, I'll try in some minutes. -- Cheers, Carlos Robinson
On Thursday 16 October 2003 14:00, Carlos E. R. wrote:
The 03.09.18 at 10:28, Dave Smith wrote:
(in other words, I am need to spawn script B from script A in separate process).
Adding an ampersand (&) at the end of a command launches it as another process. You should probably use 'sudo' to give it root privileges.
However, the parent script doesn't exit till the child exits.
-- Cheers, Carlos Robinson
Look up nohup. (info nohup) nohup <command> & -- _____________________________________ John Andersen
The 03.10.17 at 00:37, John Andersen wrote:
However, the parent script doesn't exit till the child exits.
Look up nohup. (info nohup)
nohup <command> &
Could be... I'm using 'at', and it works, so I'm reluctant to try O:-) -- Cheers, Carlos Robinson
Does bash allow for functions?
CWSIV
On Fri, 17 Oct 2003 12:26:26 -0700 Kastus
Parent process DOES exit. Please try yourself the following example:
a.sh: -------------------------------- #!/bin/bash date echo in a.sh before calling b.sh echo a.sh runs as PID $$ ./b.sh & date echo b.sh started in background -------------------------------
b.sh: ------------------------------ #!/bin/bash echo running sleep... sleep 20 echo back from sleep -----------------------------
kastus@kastus:~> ./a.sh Fri Oct 17 12:21:48 PDT 2003 in a.sh before calling b.sh a.sh runs as PID 6732 Fri Oct 17 12:21:48 PDT 2003 b.sh started in background kastus@kastus:~> running sleep...
kastus@kastus:~> ps x |grep 6732
________________________________________________________________ The best thing to hit the internet in years - Juno SpeedBand! Surf the web up to FIVE TIMES FASTER! Only $14.95/ month - visit www.juno.com to sign up today!
On Sun, 19 Oct 2003 14:49, Carl William Spitzer IV wrote:
Does bash allow for functions? CWSIV
Yes, have a look at the Advanced Bash-Scripting Guide http://www.tldp.org/guides.html Chapter 23. Functions Like "real" programming languages, Bash has functions, though in a somewhat limited implementation. A function is a subroutine, a code block that implements a set of operations, a "black box" that performs a specified task. Wherever there is repetitive code, when a task repeats with only slight variations, then consider using a function. http://www.tldp.org/LDP/abs/html/functions.html -- Regards, Graham Smith ---------------------------------------------------------
participants (8)
-
Andrei Verovski
-
Carl William Spitzer IV
-
Carlos E. R.
-
Dave Smith
-
Graham Smith
-
John Andersen
-
Kastus
-
Micxz