#!/bin/sh ############################################################################################## # # # listvms R00-00.01 # # # # ========================================================================================== # # # # Purpose: # # # # This script is used to list the Virtual Machines running on the system. # # # # ========================================================================================== # # # # Arguments: # # # # # # ========================================================================================== # # # # Programming Notes: # # # # # # ========================================================================================== # # # # Revision: # # # # Revision Who When Why # # ========= =========== =========== ===================================================== # # R00-00.00 DRLJr/I-AS 30/Apr/2014 Created # # R00-00.01 DRLJr/I-AS 16/May/2014 Check and insure the qemu entry is the executable. # # # ############################################################################################## #============================================================================================# # # #============================================================================================# get_data() { PSCMD="-e -o pid,args" # /bin/ps ${PSCMD} | /bin/grep qemu | /bin/grep -v grep return 0 } #============================================================================================# # # #============================================================================================# extract_data() { PID="$1" EXE="$2" shift 2 NAME="Not-Set" while ( true ) do if [ "$1" = "-name" ] ; then NAME="$2" shift 1 fi shift 1 if [ "$1" = "" ] ; then break fi done if [ "${NAME}" = "Not-Set" ] ; then echo "${EXE}" | /bin/grep -q qemu 1> /dev/null 2> /dev/null EOT=$? else EOT=0 fi if [ ${EOT} -eq 0 ] ; then PID=" ${PID}" PID="${PID: -6: 6}" echo "${PID} ${NAME}" fi return 0 } #============================================================================================# # # #============================================================================================# process_data() { if [ "${QUIET}" != "Y" ] ; then echo "Pid Name " echo "------ -------------------------------------------------------------------------" fi while ( true ) do read LINE EOF=$? if [ ${EOF} -ne 0 ] ; then break fi # echo " " # echo "Line:${LINE}" # echo " " extract_data ${LINE} done } #============================================================================================# # # #============================================================================================# if [ "$1" = "-h" -o "$1" = "--help" ] ; then echo " " echo " Usage: $0 -h | --help | -q | --quiet " echo " " echo " -h : Show this help screen " echo " --help : Show this help screen " echo " -q : Do not display header " echo " --quiet : Do not display header " echo " " EOT=0 else if [ "$1" = "-q" -o "$1" = "--quiet" ] ; then QUIET="Y" else QUIET="N" fi export QUIET if [ "${QUIET}" != "Y" ] ; then echo " " fi get_data | process_data if [ "${QUIET}" != "Y" ] ; then echo " " fi EOT=0 fi ############################################################################################## # # ##############################################################################################