virsh – show ip address of all running VMs

If you are using the libvirt and associated tools, then you must be aware about virt-manager. However this being a GUI tools, it is not possible to always use this. “virsh” is a good option for this.

To start with, if you need to know all the VMs all the running VMs, then you can use (to only view the names):

virsh list --name

Extending this to make it more useful is the case if you need to know the IP address for the running VMs. Here is a simple code that you can put in alias or function that can be used to get the IP address of the running VM’s.

virsh list --name | \
while read line 
do
      [[ ! -z $line ]] && virsh domifaddr $line
done

Bonus note:
If you want to start the VM, then you can use

virsh start

image ordering by Original Date Time using bash script

Here is the script:

#!/bin/bash -
#===============================================================================
#
#          FILE: imgOrg.sh
#
#         USAGE: ./imgOrg.sh
#
#   DESCRIPTION:
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka)
#      REVISION:  ---
#===============================================================================

for i in *
do
    if [[ $(file $i) == *image* ]] 
    then
        echo "Image file is :: $i"
        dir=$( exiftool -s -DateTimeOriginal $i | awk -F':' '{print $2"/"$3}')
        mkdir -p $dir
        cp $i $dir/
    else
        echo "Excluding $i"
    fi
done

 

Script looks at the DateTimeOriginal parameter in output of exiftools ( which is basically the date and time image was taken) and then puts the images in the folder in format YYYY/MM.

Disk usage by file type

Trying to find the total usage for each of the file types by extension, then here is a quick bash function for you :

disk_usage_type () 
{ 
    find . -name '*'$1 -ls | awk '
    BEGIN{
        a[0]="Bytes";
        a[1]="KB";
        a[2]="MB";
        a[3]="GB";
    }
    {sum+=$7; files++;}
    END{
    print "Total sum is ::\t" sum;
    print "Total files  ::\t" files;
        while (sum > 1024) {
            sum=sum/1024;
            count++;
            };
        print sum" "a[count];
    }'
}

Just define the function in one of your bash startup files. After that to use the function pass in the extension for which you would like to find the total size. Output should be something like below:

Total sum is ::    2586694320
Total files  ::    149
2.40905 GB