Monday, December 22, 2008

Don't Go Away Mad...

Ok, it has been a little while since the last post, but hey, I don't create magic that often (never if you ask my wife).

One of the things we were dealing with is an automated flow that deleted our Virtual Machines. This is a good thing if you want the VM's gone but in our case we kind of wanted them there but they kept getting deleted. Needless to say this was NOT a good thing. I was able to come up with a solution. We modified the delete script to a rename script.

Here is how it works....

The script was using "rm vm_name" and with a little trial and error I came up with...



mv vm_name vm_name.`date +"%Y%m%d"`_`date +"%H%m"`

Now that seems complex but it moves (hence the mv command" from the vm_name directory to vm_name.yearmonthday_hourminute .. for example a VM named vm01 decomissioned on December 19th at 11:15 am would be...

vm01.20081219_1115

Now it it would still be resident on the disk but it would show when it was decomissioned. This will help if you want to keep VM's around for 30 days or so before deleting them.

Also some other steps were not covered.. the vmware-cmd was used for all the shutdown and unregistering of the VM's..

Hope this helps somone..

Tuesday, December 2, 2008

Perl and the Array..

Ok this is not going to be much fun for the average person but I found it helpful. Figured I would put it out here for everyone to ponder.. much like the meaning of life, why are we here, how my belly button fills with lint. The REALLY important stuff.

I was working on a small script ( I really do not call it a program). In this script, I needed to find the most recent log file on a Linux box and do something with it. How I accomplished this was a rather cumbersome Perl script but here goes:

1. I was able to sort the data by using "ls -c". This put the newest log file on top.
2. The I was able to pipe that data into an array. If you are not familiar with an array, it stores information in separate entries kind of like of a database.
3. Since I wanted the first entry in the array I was able to pull it using the following code:

@item_wanted = $array_i_am_using[0];

Then I can print the array item out if needed etc.

Hope this helps someone.

I might be reading this later in the future :)