[CODE] basic (and stupid) bash script

hi.

i developed a quick script to get info (template and images) from an VM ID.

$ cat /usr/bin/onealfeijoo
#!/bin/bash

iFile_a=/tmp/$1.onealfeijoo_a
iFile_b=/tmp/$1.onealfeijoo_b

onevm show $1 > $iFile_a

function trunck {
	echo $1 | awk 'BEGIN {FS="\""}{print $2}'
iVar=`echo $1 | awk 'BEGIN {FS="\""}{print $2}'`
}

function oimage {
	oneimage list | grep $1 | head -n 1
}

echo "VMID: "$1

while read line
do

	case $line in

		TEMPLATE_ID*)
				echo -n "Template ID: "
				trunck $line
				onetemplate show $iVar > $iFile_b

				while read line2
				do
					case $line2 in

						IMAGE_ID*)
							echo -n "Image ID: "
							trunck $line2
							oimage $iVar
							;;
						IMAGE=*)
							echo -n "Image NAME: "
							trunck $line2
							oimage $iVar
							;;
					esac
				done < $iFile_b
				;;
	esac

done < $iFile_a


rm -fr $iFile_a $iFile_b

the sample output is like:

$ onealfeijoo 47411
VMID: 47411
Template ID: 123
Image ID: 110
 110 sistemas   oneadmin   rt.image                                        default         4G OS   Yes used    1
Image ID: 111
 111 sistemas   oneadmin   CESGA ac-rt datablock                              default        14G DB    No used    1

I know is so simple but maybe can help to someone for implement a cool-ruby-script-based hehe

2 Likes