0

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:

  1. how do I sort the datas in the arrays
  2. how do I know the most or less vm's uptime
  3. 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")
  4. how do I know who has just rebooted (0:0:0 or 0:0:5)

Thanks

moengoet
  • 1
  • 1
  • 4

1 Answers1

0

You could pipe the output, comma delimited for example, to the 'sort' command.

ct_
  • 2,269
  • 1
  • 16
  • 28