Would it be possible to throw a command, which goes through all the config files, and make me a list of vms, that are on one specific storage?Not directly, but you can go through all configuration files, extract the ones on your storage and shutdown the VMs.
cat /etc/pve/nodes/server/qemu-server/*.conf|grep "local2"
Hello,
somethin easy like:
Code:cat /etc/pve/nodes/server/qemu-server/*.conf|grep "local2"
Replace all <between> with your values
cat /etc/pve/nodes/<your server name>/qemu-server/*.conf|grep "l<your storage name>"
or when you want to get all disks from every servers in a cluster
cat /etc/pve/nodes/*/qemu-server/*.conf|grep "l<your storage name>"
Best regards
Guenter
You don't need to cat first, just run grep directly on the files and extract the vmid to shut down.
root@proxmox:/etc/pve/qemu-server# grep harddisk *conf | cut -d: -f1 | sed -s 's/\.conf//' | sort -u
10000
10001
root@proxmox:/etc/pve/qemu-server# for vm in $( grep harddisk *conf | cut -d: -f1 | sed -s 's/\.conf//' ); do qm shutdown $vm; done
Thanks you very much.Okay, let's built if for you:
Code:root@proxmox:/etc/pve/qemu-server# grep harddisk *conf | cut -d: -f1 | sed -s 's/\.conf//' | sort -u 10000 10001
This yields all VMs with given storage named 'harddisk'. You can then just do a little loop around to stop the VMs:
Code:root@proxmox:/etc/pve/qemu-server# for vm in $( grep harddisk *conf | cut -d: -f1 | sed -s 's/\.conf//' ); do qm shutdown $vm; done
root@pvetest:~# grep local-lvm /etc/pve/nodes/*/qemu-server/*.conf | cut -d: -f1 | sed -s 's/\.conf//' | sort -u
/etc/pve/nodes/pvetest/qemu-server/100
/etc/pve/nodes/pvetest/qemu-server/101
root@server:/etc/pve/nodes# grep local2 *conf | cut -d: -f1 | sed -s 's/\.conf//' | sort -u
grep: *conf: No such file or directory
root@server:/etc/pve/nodes# for vm in $( cat /etc/pve/nodes/server/qemu-server/*.conf | grep "local2" |awk -F":" '{ print $3 }'|cut -d"/" -f1 ); do qm status $vm; done
status: stopped
your command give me this:Bash on liners, I like them!
But if I use your example I get:
Code:root@server:/etc/pve/nodes# grep local2 *conf | cut -d: -f1 | sed -s 's/\.conf//' | sort -u grep: *conf: No such file or directory
So when I use your for with mine advanced example this works:
Code:root@server:/etc/pve/nodes# for vm in $( cat /etc/pve/nodes/server/qemu-server/*.conf | grep "local2" |awk -F":" '{ print $3 }'|cut -d"/" -f1 ); do qm status $vm; done status: stopped
Best regards
Guenter
root@pvetest:~# for vm in $( cat /etc/pve/nodes/*/qemu-server/*.conf | grep "local-lvm" |awk -F":" '{ print $3 }'|cut -d"/" -f1 ); do qm status $vm; done
400 Parameter verification failed.
vmid: type check ('integer') failed - got 'vm-100-disk-1,size=2G'
qm status <vmid> [OPTIONS]
400 Parameter verification failed.
vmid: type check ('integer') failed - got 'vm-101-disk-1,size=2G'
qm status <vmid> [OPTIONS]
root@pvetest:~# for vm in $( cat /etc/pve/nodes/*/qemu-server/*.conf | grep "local-lvm" |awk -F"-" '{ print $3 }'|cut -d"/" -f1 ); do qm status $vm; done
status: stopped
status: stopped
Yes I was already playing with this method. Only problem is, it doesnt tell me what storage the vm is on, which is what I need for this script.Code:qm list >> textfile.txt
Will save a textfile with a list of all machines and if you play around you will get
Code:qm list|grep running >> textfile.txt
This are all Linux "basics"
Over and out
This are all Linux "basics"Code:qm list|grep running >> textfile.txt
We use essential cookies to make this site work, and optional cookies to enhance your experience.