#!/bin/bash

#if ( sudo qm config $1 | grep '^name:' | awk '{print $2}' ); then sudo pct config $1  | grep '^hostname:' | awk '{print $2}'; fi


VM=$1

[ -n "$VM" ] && [ "$VM" -eq "$VM" ] 2>/dev/null
if [ $? -ne 0 ]; then
   PARAM="name"
fi

if [ "$PARAM" = "name" ]; then
  if ( sudo pct list | grep "$VM" >/dev/null ); then 
    sudo pct list | grep "$VM" | awk '{print $1}'
  else
    sudo qm list | grep "$VM" | awk '{print $1}'
  fi
else
  if sudo pct list | grep "$VM" >/dev/null; then
    sudo pct list | grep "$VM" | awk '{print $3}'
  else
    sudo qm list | grep "$VM" | awk '{print $2}'
  fi    
fi






# sudo pct list | grep '13002' | awk '{print $3}'

# sudo qm list | grep 13001 | awk '{print $2}'
# sudo qm list | grep 'kat-gate' | awk '{print $1}'