LeRoy Cressy on 7 Jan 2004 15:07:02 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] How to find parent in the shell?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael C. Toren wrote:
On Tue, Jan 06, 2004 at 03:11:11PM -0500, Stephen Gran wrote:

I don't see how testing to see if your parent process is init will give
you any insight into weather or not your script is being executed at boot
time or not, unfortunately.  What if a user types "exec
/etc/init.d/whatever" from a console login shell?

Well, that would actually be fine. The only thing I am trying to do is have the script run at boot, but not be rerun on upgrade.


If you don't mind being dependent on /proc and bash, perhaps:

	#!/bin/bash

	set -e
	pid=$$

	while [ $pid -gt 1 ]
	do
	    ppid=$(awk '/^PPid:/ {print $2}' /proc/$pid/status)
	    tr '\0' ' ' < /proc/$pid/cmdline | awk '{print $1}' | \
		awk -F/ '{print $NF}' | grep -q ^dpkg && exit 1
	    pid=$ppid
	done

The above script traces it's lineage back to init, and if it finds an
ancestor named "dpkg*", it dies with an exit status of 1.  Otherwise,
it exits cleanly.

-mct

I have a question, since this is a boot script that you are using for system startups, how about the Debian install boot scripts which only have ash? Since bash is not even part of the install scripts if your script gets on the install disks it will not run if /bin/bash is not available.



- -- Rev. LeRoy D. Cressy mailto:leroy@lrcressy.com /\_/\
http://lrcressy.com ( o.o )
Phone: 215-535-4037 > ^ <
FAX: 215-535-4285


gpg fingerprint:  62DE 6CAB CEE1 B1B3 359A  81D8 3FEF E6DA 8501 AFEA

For info on enigmail:    http://lrcressy.com/linux/mozilla.pdf
For info on gpg:         http://www.gnupg.org/

Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me. (John 14:6)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Netscape - http://enigmail.mozdev.org

iD8DBQE//CBJP+/m2oUBr+oRAnwLAJ9IvrhYRGG/vxGCpLx8s3MS3Iz6fACeMU7n
OlrKKYzlNxqvQCxeWMSTk5k=
=+hAW
-----END PGP SIGNATURE-----

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug