I have a simple script to count / grab every uptime of each VM on xen (using: xm uptime)
xm uptime |grep vm |awk '{print $1}' > /uptime.txt
IPS="/uptime.txt"
VMDB=$(grep -Ev "^#" $IPS)
for i in $VMDB
do
days=$(xm uptime |grep $i |awk '{print $3}')
hrs=$(xm uptime |grep $i |awk '{print $5}' | sed 's/[:,]/ /g' | awk '{print $1}')
mins=$(xm uptime |grep $i |awk '{print $5}' | sed 's/[:,]/ /g' | awk '{print $2}')
uptimesecs=$(($mins*60))
uptimesecs=$(($hrs*3600+$uptimesecs))
uptimesecs=$(($days*86400+$uptimesecs))
echo "$uptimesecs seconds uptime for $i"
done
but the problem is:
- how do I sort the datas in the arrays
- how do I know the most or less vm's uptime
- sometimes the VM's uptime consist of only hours:minutes:seconds (usually it displays days hours:minutes:seconds, so the above script gave an error for those encountered) >> *60: syntax error: operand expected (error token is "*60")
- how do I know who has just rebooted (0:0:0 or 0:0:5)
Thanks