| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 | #!/bin/bash# Just die if not root.if [ ${UID} -ne 0 ]; then    echo "FATAL: Need to run as root."    exit 1fi# Die if not running with CAP_SYS_PACCTif [ -z "$(capsh --decode=$(cat /proc/self/status | grep ^CapEff | cut -f2) | grep sys_pacct)" ]; then    echo "FATAL: Need CAP_SYS_PACCT to run."    exit 1fi# Die if running as PID 1 (no access to host PID namespace)if [ $$ -eq 1 ]; then    echo "FATAL: Need access to host PID namespace, can't seriously be PID 1."    exit 1fi# Shutdown handler.trap_shutdown() {    echo "Shutting down..."    exit 0}trap trap_shutdown SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM# Announce collection period.PERIOD=10if [ -n "$1" ]; then    PERIOD=$1fiecho "Reporting on process activity every ${PERIOD} seconds."# Did someone ask for cumulative stats?case ${CUMULATIVE:-0} in    1|yes|true)	echo "Gathering cumulative accounting data since container start."	CUMULATIVE=1	;;    *)	echo "Clearing accounting data between snapshots."	CUMULATIVE=0	;;esac# Clean up /var/account/pacct on startup if so requested.case ${STARTUP_SCRATCH:-0} in    1|yes|true)	echo "Removing existing accounting data due to scratch-on-startup being ${STARTUP_SCRATCH}..."	rm -f /var/account/pacct*	;;    *)	echo "Skipping scratch-on-startup..."	;;esac# Make sure we have everythingecho "Making sure /var/account/pacct is ready..."/usr/libexec/psacct/accton-create# Start accounting/usr/sbin/accton /var/account/pacct# Do the loopwhile [ 1  ]; do    sleep ${PERIOD}    # Report after waking up.    #	Looks like the choice is between paging and I/O, can't have both.    # This one prints paging info...    /usr/sbin/sa -ajlp > /var/account/psacct-dump-all    # ...and this one prints total I/O operations (which seems to be unsupported).    #/usr/sbin/sa -ajlD > /var/account/psacct-dump-all    # This is less than very useful.    #/usr/sbin/dump-acct /var/account/pacct > /var/account/psacct-dump-raw    # Could make a CSV out of the above "sa":    #   | tr -s' ' | sed 's/^ //; s/ /,/g'    # Did we say NOT cumulative data?    if [ ${CUMULATIVE} -eq 0 ]; then	echo -n > /var/account/pacct    fidone# End of entrypoint-psacct.sh
 |