#!/bin/bash # released 11 Nov 2006 by grummund and yager on irc.chatspike.net#RapidVPS # this util expects to receive /proc/user_beancounters via stdin # unprivileged users may use beanc.c from http://www.labradordata.ca/home/35 # primary reference: http://wiki.openvz.org/Proc/user_beancounters # also http://forum.swsoft.com/showthread.php?s=d03fd7e49b67dfb1f45f4f453e019a73&threadid=26770 ## Output option defaults to everything except explanations: option_date=y; option_datehost=y; option_uptime=y option_limits=y; option_usage=y option_memory=y; option_kernel=y option_others=y; option_failcnts=y option_demarcations=y; option_explanations=n option_help=y; option_veid=y exp0="******" # around the explanation text ## Array field constants: param_name=0; held=1; maxheld=2; barrier=3; limit=4; failcnt=5 declare -a FailCounts FailCounts[0]=0 fails=0 demarcate () { echo '-----------------------------------------------' } read_params () { case $# in 2) UBC_version="$2"; return;; 7) UBC_veid="${1%:}"; shift;; 6) ;; *) return 1;; esac PARAM=$1 let UBC_$PARAM[1]=$2 let UBC_$PARAM[2]=$3 let UBC_$PARAM[3]=$4 let UBC_$PARAM[4]=$5 let UBC_$PARAM[5]=$6 # eval echo "debug: $PARAM= \${UBC_$PARAM[@]}" let fails=UBC_$PARAM[5] if [ $fails -gt 0 ] && [ $6 != "failcnt" ] then let "FailCounts[0] += 1" FailCounts[${FailCounts[0]}]="$*" fi } ## A couple handy functions: Return_Val= # Global variable to hold oversize return value of function. kilos () { Return_Val=$(($1 / 1024)) return } megas () { kilos $1 # Return_Val=$(($Return_Val / 1024)) let "Return_Val /= 1024" return } print_bytes () { if [ "$2" -gt 1048576 ]; then printf "$1" "$(($2 / 1048576))" "MB" elif [ "$2" -gt 1024 ]; then printf "$1" "$(($2 / 1024))" "KB" else printf "$1" "$2" "B" fi } ## parse the command line arguments: for arg in $@; do case ${arg:0:1} in +) option_state=y;; -) option_state=n;; esac char=1 while [ $char -lt ${#arg} ] ; do case ${arg:$char:1} in v) option_veid=$option_state;; i) option_datehost=$option_state;; s) option_uptime=$option_state;; l) option_limits=$option_state;; u) option_usage=$option_state;; m) option_memory=$option_state;; k) option_kernel=$option_state;; o) option_others=$option_state;; f) option_failcnts=$option_state;; d) option_demarcations=$option_state;; e) option_explanations=$option_state;; H) option_veid=$option_state option_datehost=$option_state option_uptime=$option_state;; a) option_datehost=$option_state option_uptime=$option_state option_limits=$option_state option_usage=$option_state option_memory=$option_state option_kernel=$option_state option_others=$option_state option_failcnts=$option_state option_demarcations=$option_state option_explanations=$option_state option_veid=$option_state esac char=$[$char+1] done # while case $arg in -h|+h|--h|--help) cat <