bash script: calling pvesh within a loop exits after first iteration

esteco

New Member
Feb 7, 2014
3
0
1
Hello there,
I'm trying to write a bash script that will help me manage VMs automatically.
My goal is to manage VMs power status qutomatically, the approach is (within the bash script itself):
- run pvesh and get the cluster status, save the output to a tmp.file
- parse the tmp.file and load values of interesting VMs (any qemu and running VM)
- "build up" to a correct syntax a "pvesh get" status command, to check the VM status
- cycle to the next valid VM till EOF

So, if I run this script in "test" mode (i.e. just "build" a pvesh syntax in a $CMD variable then echo $CMD) the loop completes to EOF; if I execute the $CMD instead of just printing it, $CMD executes correctly for the first instance, then exits the loop as if EOF is reached.

Here is the script attached, please forgive my naif bash programming (and perhaps give me an hint to enhance it)

View attachment pvesh_script_sh.txt
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!