Irregular Expressions

February 5, 2010  9:20 PM

Finding VM snapshots – Part 2

Dan O'Connor Dan O'Connor Profile: Dan O'Connor

Using find to locate vm’s with snapshots is easy.

`find /vmfs/volumes/ -type f -name "*00*.vmdk" | awk -F "/" '{print $1"/"$2"/"$3"/"$4"/"$5 }' | uniq`

Find is just not limited to locating the files but it is able to preform actions on it. Using the `-exec` allows any command to be executed.

`find /vmfs/volumes/ -type f -name “*00*.vmdk” -exec ls -alh {} \;`

Will execute `ls -alh` on each file that matches the parameters of the find command.  Adding this will provide date stamps on the files if needed.

Find can also work with dates itself, `-mtime` can be used to give find parameters on the last modified time of a file.  This can be specified in blocks of 24 hours, `-mtime +1` will give files last changed two days ago, not 1, this is because fractions of days are ignored.  Find can also be given multiple date parameters to narrow down the returned results as desired.

February 3, 2010  11:20 AM

Finding VM snapshots – Part 1

Dan O'Connor Dan O'Connor Profile: Dan O'Connor

Locating VM’s with snapshots on a datastore is easy if you know how to use the find command.

`find /vmfs/volumes/ -type f -name “*00*.vmdk”` Will look through the /vmfs/volumes/ looking for files with names that match the provided pattern.

More specifically the folders those files are stored in is needed.

AWK can be used to just pull that information back, `find /vmfs/volumes/ -type f -name “*00*.vmdk” | awk -F “/” ‘{print $1″/”$2″/”$3″/”$4″/”$5 }’`.  This output is getting useful but we really don’t need to see the same folder over and over again.

`find /vmfs/volumes/ -type f -name “*000*vmdk*” | awk -F “/” ‘{print $1″/”$2″/”$3″/”$4″/”$5 }’ | uniq` will only return the unique results.  Appending a -c to the `uniq` will provide a count of the number of times that pattern appeared.

I am using this command in two ways, first is the `uniq` with out -c  piped to `wc -l` to get a count of all of the vm’s with snapshots.   The second is with`uniq -c` piped to `sort -rn` to give the number of disks that have snap shots in each VM.

February 1, 2010  5:08 PM

Using vdf to report on storage usage

Dan O'Connor Dan O'Connor Profile: Dan O'Connor

VMWare has some excellent command-line tools.

vdf will produce a list of mounts on the system and the associated storage used for each mount point, exactly like df but this will include the vmfs volumes.

You can produce a nice output of this information using awk and grep.

vdf -h | grep -E ‘^\ +[0-9]’ | awk ‘{ print $4″ “$5 }’ | sort -rn | awk ‘{ print $2” “$1 }’

The lines that you are interested in start with multiple spaces then numbers so “grep -E ‘^\ +[0-9]’ ”

The first awk is used to pull out the name of the storage unit and the associated usage %. “awk  ‘{ print $4” “$5 }'”

Sort is then used to sort it with the highest usage on top. “sort -rn”

Then the last awk is used to print out name then usage, this is just a personal preference. “awk ‘{ print $2” “$1 }’ ”

Now with this nice formatted data you can pull this in to your central logging device and create some charts and alerts.

/vmfs/volumes/NAME 44%

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: