#!/bin/sh - # # Oliver Fromme # # BSD-style copyright and standard disclaimer applies. # # Note: This script works for FreeBSD 4.x only! # For FreeBSD 6.x, please use jls(1) which is already # part of the FreeBSD base system, and jps: # http://www.secnetix.de/~olli/scripts/jps # # This script uses ps and /proc/*/status to display an # overview of jailed processes. This is particularly # useful when you run several jails on your machine. # # Notes: # - procfs must be mounted on /proc. # - This script doesn't work inside a jail, of course. # # # Format of "ps -auxww" output (example): # # $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 # USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND # root 6870 0.0 2.1 3792 816 ?? IsJ 20Sep01 0:21.31 /sbin/sshd # # Format of /proc/*/status (example, one line): # # $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 # CMD PID PPID PGID SID CTTY FLGS START UTIME STIME # sshd 6870 1 6870 6870 -1,-1 sldr 1001021455,773724 20,778070 0,487756 # # $11 $12 $13 $14 $15 # WCMSG EUID UID EGID,GIDS HOSTNAME # select 0 0 0,0,0,2,3,4,5,20,31 jail01.haluter.fromme.com # A=$(printf '\001') { echo "USER${A}PID${A}HOSTNAME${A}COMMAND" ps -auxww \ | awk ' ($8~/J/) { status_file = "/proc/" $2 "/status"; if ((getline status 0) { split (status, st); printf "%s\001%s\001%s\001", $1, $2, st[15]; for (i = 11; i <= NF; i++) printf "%s ", $i; printf "\n"; } close (status_file); } ' \ | sort -t "${A}" +2 } | column -t -s "${A}" #--