Files
q-tools/anduril/csc_vm_status_query
2014-12-13 22:33:33 +02:00

76 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
help='CSC Virtual Machine Load Status
-s Short (default)
-l Long
-c Do not pretty print short output
-b [l|m] return the name of the node with l=least load, m=least used memory
-u [username] return a list of nodes with processes of given user
L=Load, M=used memory + cached / total, U=users with processes
'
mode="short"
postprocess=" | sort -V | ncsv -c -i' ' -d' ' "
while getopts "clshu:b:" OPTS;
do case ${OPTS} in
s)
mode="short"
;;
l)
mode="long"
;;
c)
postprocess=""
;;
b)
mode="best"
[ "$OPTARG" = "l" ] && bestcol=3
[ "$OPTARG" = "m" ] && bestcol=6
if [ -z "$bestcol" ]
then echo "Argument to -b not recognized"
echo "$help"
exit
fi
;;
u)
mode="user"
username=$OPTARG
[ -z "$username" ] && exit
;;
h)
echo "$help"
exit
;;
?)
echo "$help"
exit
;;
esac
done
if [ "$OPTIND" -gt 1 ]
then shift $(( $OPTIND-1 ))
fi
status_folder="/mnt/csc-gc5/vm_state"
if [ ! -d "$status_folder" ]
then echo $status_folder not mounted
exit
fi
if [ "$mode" = "short" ]
then eval "cat $status_folder/*short $postprocess"
fi
if [ "$mode" = "long" ]
then eval "cat $status_folder/*long"
fi
if [ "$mode" = "best" ]
then eval "cat $status_folder/*short" | sed 's,[|/:\+], ,g' | sort -k $bestcol -n | cut -d" " -f2 | head -n 1
fi
if [ "$mode" = "user" ]
then eval "grep $username $status_folder/*long" | sed -e 's,.*/,,' -e 's,\..*, ,' | tr -d [:cntrl:]
echo ""
fi