How to kill a KVM virtual machine in Promox via the command line or terminal

  Sometimes a Proxmox KVM VM will stop responding to the GUI’s attempts to shut it down; fortunately it’s easy to shut it down from the command line. Make note of the VM ID (next to the name of the VM in the left pane of the Proxmox GUI), log into the server via SSH as root and run:  
qm stop [vmid]
qm stop 124
  Check back in the GUI a few seconds later and you should see that the KVM has stopped.

How to kill a process after a set period of time

  Knowing how to limit how long a process will run for is quite useful, particularly when you have daily backup scripts and the like which may at times run more than 24 hours; having multiple processes attempting to synchronize the same files can waste time, bandwidth and CPU power needlessly. The command we will use here is timeout. Ubuntu Server should have this pre-installed. It is used so:  
timeout [no. of seconds] [command]
timeout 10 rsync /home/user/files/ /backups/user/files/
  would run the above rsync command but kill it after 10 seconds.   This can be particularly useful with your daily scripts; simply set the timeout to be a few minutes less than 24 hours and you should hopefully avoid them running over each other. For reference there are 3600 seconds in an hour and 86400 seconds in 24 hours; setting a process to timeout after 86000 seconds would result in it running for 23 hours, 56 minutes and 20 seconds.

see singles without signing up
  If you’re writing scripts or making cron jobs you will need to know the full path of the commands you’re using; rather than just being able to use “ls” you would have to use “/bin/ls” instead. You could use the find command here but there’s a quicker and more elegant way: which. Use it like so:  
which ls
  will return:  
  Not everything will be in /bin, e.g.:  
which timeout
  will likely return:  
  Simple but it will make your life quite a bit easier when writing scripts, particularly with new commands or command which you don’t use often.

ESXi: Entering and exiting maintenance mode via command line

  Following on from yesterday’s post, here is how to enter or leave maintenance mode on an ESXi host via SSH:  
vim-cmd hostsvc/maintenance_mode_enter
  to go into maintenance mode – and to leave it:  
vim-cmd hostsvc/maintenance_mode_exit
  If you’re interested in other useful commands, you can see more hostsvc options by running:  
vim-cmd hostsvc
  This is a useful command to know as it is one of the critical steps in applying some patches to ESXi remotely.

How to find which version of ESXi you’re running from the command line?

  If you’re remotely logging in to a server to apply the latest patch but can’t remember whether you’re running 4, 4.1, 5.0 or 5.1 – and it can certainly happen when you’re managing quite a few of them remotely – there is a handy command to see which version and build number you’re actually using. After you’ve SSH’d in, run:  
vmware -v
  This will display output along the lines of the following:  
VMware ESXi 5.0.0 build-469512
  You can also use:  
vmware -l
  which doesn’t display the build number:  
VMware ESXi 5.0.0 GA
  Straightforward but very handy if you haven’t got the proper notes with you.

How to exclude results from grep

  Sometimes you may wish to further filter grep output, such as in the following situation:  
# zfs get all | grep compressratio backup01         compressratio         1.23x                  – backup01         refcompressratio      1.00x                  – backup01/data    compressratio         1.50x                  – backup01/data    refcompressratio      1.50x                  – backup01/photos  compressratio         1.05x                  – backup01/photos  refcompressratio      1.05x                  –
Here we only really want to see the compressratio results, not the refcompressratio. We can pipe the grep output to another grep command, this time inverting the results with the -v switch.  
# zfs get all | grep compressratio | grep -v refcompressratio backup01         compressratio         1.21x                  – backup01/data    compressratio         1.50x                  – backup01/photos  compressratio         1.05x                  –
This excludes any line containing refcompressratio, making the results easier to read. This is particularly helpful when you have a large number of results from grep.