How to check if script invoked from main shell
Phil Sutter
phil.sutter at viprinet.com
Fri Jul 27 08:47:30 UTC 2012
Hi,
On Fri, Jul 27, 2012 at 10:20:35AM +0200, Harald Becker wrote:
> As here are many shell script experts a not so Busybox related
> question, except I'm using Busybox ash and want to use only builtin
> applets:
>
> I need to change behavior of shell script(s) if they get invoked from a
> main shell, that is a shell (interactive or not) which is a direct
> child of process #1 (init). How to determine if script has been invoked
> in this environment? What is the best/easiest solution for this?
>
> An example to clarify my needs:
>
> I have a shell invoked from init:
>
> $ echo "pids=$$,$PPID"
> pids=156,1
>
> And a multi function script command invoked by root in several
> situations:
>
> File /root/bin/doit:
>
> #!/bin/busybox sh
> echo "script pids=$$,$PPID"
> exit 0
>
> $ doit
> script pids=1007,156
>
> How does this doit script know if it is invoked from a top level shell
> in the shown sense or from any other shell (not direct child of init
> process)?
You could perhaps try to:
| grep -q '^PPid:[[:space:]]*1$' /proc/$PPID/status' \
| && echo "parent is child of init" \
| || echo "parent is no child of init"
HTH, Phil
--
VNet Europe GmbH
Mainzer Str. 43
55411 Bingen am Rhein
Germany
Management Buy-Out at Viprinet - please read
http://www.viprinet.com/en/mbo
Management Buy-Out bei Viprinet - bitte lesen Sie
http://www.viprinet.com/de/mbo
Phone/Zentrale: +49 6721 49030-0
Direct line/Durchwahl: +49 6721 49030-134
Fax: +49 6721 49030-109
phil.sutter at viprinet.com
http://www.viprinet.com
Registered office/Sitz der Gesellschaft: Bingen am Rhein, Germany
Commercial register/Handelsregister: Amtsgericht Mainz HRB44090
CEO/Geschäftsführer: Simon Kissel
More information about the busybox
mailing list