SUMMARY: PSTREE and DHCP

From: Ing. Felipe Tribaldos (felipe@pty.com)
Date: Thu Nov 21 1996 - 07:05:34 CST


Hi;

Following my search for some utils.
I'm running Solaris 2.4 BTW I forgot to mention.
I was informed by many that Solaris 2.5 comes with a host of
utils including a process tree under /usr/proc/bin

A couple of folks sent me scripts that do the job under 2.4.
Both are attached at the end of the file. One is a perl script and
the second is a /bin/sh script.

Nobody seems to know much about DHCP for UNIX. I guess this must be
a windoze thing? However one of the main reasons to run DHCP is
security, on a LAN and to avoid users changing their configs.
I was pointed to a very useful DHCP FAQ
http://web.syr.edu/~jmwobus/comfaqs/dhcp.faq.html

The FAQ states that Solaris 2.6 will include a DHCP server.

Thanks once again to all that replied;

Felipe

PS scripts attached

-- 
 ___________________________________________________________________________
| Ing. Felipe Tribaldos                                                     |
| Gerente de Operaciones / Operations Manager   Tel. +(507)269-3571/223-5111|
| CyberMedia Panama                             Fax. +(507)264-6082         |
| Internet Access - Web Publishing              Res. +(507)269-7330         |
| url: http://www.pty.com/                      email: felipe@pty.com       |
| __________________________________________________________________________|

Script #1 in PERL -------------------------------------------------------------------------- #!/usr/local/bin/perl # by Karel De Bruyne

@psresult=`ps -ef`; foreach $line (`ps -ef`) { chop $line; $uid = substr($line, 0,8); $uid =~ s/ //g; $pid = substr($line, 8,6); $pid =~ s/ //g; $ppid = substr($line,14,6); $ppid =~ s/ //g; $comd = substr($line,47); $comd =~ s/^ //; $entry{$pid}=$uid."|".$ppid."|".$comd; }

$pid=0; $pre=""; print " PID PPID USER COMMAND\n"; &drawtree($pid, $pre);

sub drawtree { local($pid,$pre)=($_[0],$_[1]); ($uid,$ppid,$comd)=split(/\|/,$entry{$pid}); printf("%5s %5s %8s %s%s\n",$pid,$ppid,$uid,$pre,$comd); foreach $line (sort keys(%entry)) { ($uid,$ppid,$comd)=split(/\|/,$entry{$line}); if (($ppid eq $pid)&&($line ne $pid)) { &drawtree($line,$pre." "); } } } ------------------------------------ CUT HERE------------------------

Script #2 sh shell script

---------------------------------------------------------------------

#!/bin/sh # -a all users # -c # all processes starting with parent # # # all proces-trees with proces # # user user only # null user LOGNAME only #------------------------------------------------------------------------------- mhacat() { # $1=passwd|group awk ' BEGIN { FS = ":"; ex = 0; } /^\+/ { ex = 1; next; } { print; } END { exit ex; }' /etc/$1 || ypcat $1 } #------------------------------------------------------------------------------- if [ $# -ge 1 ] then case "$1" in -a) _test="user" _user="-a" ;; -c) [ $# -eq 2 ] || exit _test="child" _pid="$2" ;; [0-9]*) _test="pid" _pid="$1" ;; *) _test="user" _user="$1" ;; esac else _test="user" _user="${LOGNAME}" fi #------------------------------------------------------------------------------- PORT=SUN4X case "${PORT}" in CTIX5) _command="COMMAND" _stopcmd="/etc/telnetd" ;; HP980) _command="COMMAND" _stopcmd="inetd:telnetd" ;; IBM) _command="CMD" _stopcmd="/etc/inetd:/etc/telnetd" ;; SCO) _command="COMMAND" _stopcmd="inetd:telnetd:in.rlogind" ;; SUN4X) _command="COMMAND" _stopcmd="inetd:telnetd:in.rlogind" ;; U60V4) _command="COMD" _stopcmd="/usr/sbin/inetd:/usr/sbin/telnetd:/usr/lib/saf/ttymon" ## /usr/lib/saf/sac ;; *) _command="COMMAND" _stopcmd="/etc/inetd:/etc/telnetd" ;; esac #------------------------------------------------------------------------------- case "${PORT}" in DECUL) #------------------------------------- DECUL -------------------- case `uname -r` in 4.2|4.3) _offuid=62 _offpid=57 _offppid=51 ;; 4.0) _offuid=61 _offpid=56 _offppid=50 ;; *) echo "Onbekende OS-revisie (`uname -r`)" >&2 exit 3 ;; esac { mhacat passwd echo "--- start ps ---" ps -alwx 2>/dev/null } | awk ' BEGIN { ps = 0; offuid = '${_offuid}' offpid = '${_offpid}' offppid = '${_offppid}' } ps == 0 { split($0, p, ":"); if (tab[p[3]] == "") tab[p[3]] = p[1]; } $0 == "--- start ps ---" { ps = 1; next; } ps == 1 { poscmd = 69; ps = 2; next; } ps == 2 { for (j = poscmd - 1; substr($0, j, 1) != " "; j++) ; for (; substr($0, j, 1) == " "; j++) ; uid = substr($0, j - offuid, 4) + 0; pid = substr($0, j - offpid, 5) + 0; ppid = substr($0, j - offppid, 5) + 0; print tab[uid] " " pid " " ppid " " substr($0, j); }' ;; SUN4X) #------------------------------------- SUN4X ----------------------- { mhacat passwd echo "--- start ps ---" ps -alwx 2>/dev/null } | awk ' BEGIN { ps = 0; } ps == 0 { split($0, p, ":"); if (tab[p[3]] == "") tab[p[3]] = p[1]; } $0 == "--- start ps ---" { ps = 1; next; } ps == 1 { poscmd = 72; ps = 2; next; } ps == 2 { for (j = poscmd - 1; substr($0, j, 1) != " "; j++) ; for (; substr($0, j, 1) == " "; j++) ; uid = substr($0, 9, 4) + 0; pid = substr($0, 14, 5) + 0; ppid = substr($0, 20, 5) + 0; print tab[uid] " " pid " " ppid " " substr($0, j); }' ;; *) #----------------------------------------- rest ---------------------- ps -ef | awk ' NR == 1 { lencommand = length("'"${_command}"'"); for (poscmd = 1; poscmd < length($0); poscmd++) { if (substr($0, poscmd , lencommand) == "'"${_command}"'") break; } next; } { for (j = poscmd - 1; substr($0, j, 1) != " "; j++) ; for (; substr($0, j, 1) == " "; j++) ; cmd = substr($0, j); print $1 " " $2 " " $3 " " cmd; }' ;; esac | awk ' #--------------- $1=uid $2=pid $3=ppid rest=cmd ------------- $3 != 0 { pid = $2; if ("'"${_test}"'" == "user") { if ("'"${_user}"'" == "-a" || $1 == "'"${_user}"'") pidok[pid] = 1; else pidok[pid] = 0; } else if ("'"${_test}"'" == "pid") { if (pid == "'"${_pid}"'") pidok[pid] = 1; else pidok[pid] = 0; } else pidok[pid] = 0; uid[pid] = $1; ppid[pid] = $3; $1 = ""; $2 = ""; $3 = ""; cmd[pid] = substr($0, 4); } END { split("'"${_stopcmd}"'", stopcmd, ":"); ok = 1; for (pid in uid) { doit = pidok[pid]; id = pid; count = 0; while (id > 1) { if (!pidok[id] && doit) { for (i in stopcmd) { if (substr(cmd[id], 1, length(stopcmd[i])) == stopcmd[i]) ok = 2; } pidok[id] = ok; } id = ppid[id]; if (++count == 50) break; } } for (pid in uid) { doit = pidok[pid]; id = pid; p = sprintf("%05d", id); count = 0; while (id > 1) { if (id == '$$') { doit = 0; break; } if (id == ppid['$$']) { oms = cmd[ppid[id]]; if (substr(oms, 1, 3) == "ced") { doit = 0; break; } } if ("'"${_test}"'" == "user") { if (!doit && (pidok[id] == 1)) doit = 1; } else { if (!doit && id == "'"${_pid}"'") doit = 1; } id = ppid[id]; p = sprintf("%05d:%s", id, p); if (++count == 50) break; } if (doit) { printf("%-8s", uid[pid]); printf(" %s", p); printf(" %s\n", cmd[pid]); } } }' | sort +0.9 | case "${_test}" in "child") awk ' { n = split($2, l, ":"); printf("%d ", l[n]); } END { printf("\n"); }' ;; *) awk ' BEGIN { s = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "; } { n = split($2, l, ":"); if (n == 2) printf("\n"); printf("%-8s", $1); printf(" %s", substr(s, 1, 2 * (n - 2))); printf("%-5s", l[n]); $1 = ""; $2 = ""; printf(" %s\n", substr($0, 1, 65 - 2 * n)); }' ;; esac #-------------------------------------------------------------------------------



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:16 CDT