/sbin/vmfs-support cant handle spaces in filenames - can anybody help to fix it ?
If you copy vmfs-support to /tmp and make it executable with chmod 755 vmfs-support you can run it.
If you launch it with /tmp/vmfs-support /vmfs/volumes/
you will see the problem.
This is just a first step ...
Actually I want to list all flat.vmdks in /vmfs/volumes and then run this 2 simple commands:
ls -i $file >> results.txt
vmkfstools -p 0 $file >> results.txt
Whatever I do either I run into the problem with spaces in the name for the vmkfstools command or
I get a problem with ls and it says" file not found"
Thanks Ulli
Ok, I had the time to reproduce this, and understand the issue now (I think).
I did some modifications to your script, so that it doesn't need temporary files, and can also handle datastore names with spaces.
#/bin/sh
cd /vmfs/volumes/
ls -Ap | grep -v / | while read dsName
do
find "/vmfs/volumes/$dsName/" -iname '*-flat.vmdk' | while read fileName
do
echo _________________________________________________________________________________________________
ls -i "$fileName"
ls -s "$fileName"
hexdump -n 1024 -C "$fileName"
echo " "
vmkfstools -p 0 "$fileName" | grep Mapping -A5
echo " "
echo " "
vmkfstools -D -v10 "$fileName"
echo " "
echo " "
done
done
André
I haven't tesed it yet, but does
ls -i "$file" >> results.txt
vmkfstools -p 0 "$file" >> results.txt
work?
André
Thanks to Darius for the right inspiration.
I did not try to fix the existing support script and started from scratch.
Very ugly but works arounds spaces in names and issues with symlinks ...
Super ugly - needs 2 temporary file ...
But it gives me exactly what I need.
Works around problems with spaces in the names and fixes problems when following symlinks.
copy script to /tmp/z.sh
########################################################################################################
#!/bin/sh
cd /vmfs/volumes/
ls -Ap | grep -v / > /tmp/datastores.txt
cd /tmp/
echo "blabla" > /tmp/z2.sh
chmod 755 /tmp/z2.sh
for i in $(cat /tmp/datastores.txt)
do
FLATS=$( find /vmfs/volumes/$i/ -iname '*-flat.vmdk' | sed 's| |XXXX|g' | sed 's|.vmdk|.vmdk"|' | sed 's|^|"|' )
for x in $FLATS
do
echo "echo _________________________________________________________________________________________________"
echo "ls -i $x"
echo "ls -s $x"
echo "hexdump -n 1024 -C $x"
echo 'echo " "'
echo "vmkfstools -p 0 $x | grep Mapping -A5"
echo 'echo " "'
echo 'echo " "'
echo "vmkfstools -D -v10 $x "
echo 'echo " "'
echo 'echo " "'
done
done
###########################################################################################################
Must be launched as:
cd /tmp
./z.sh | sed 's|XXXX| |g' > z2.sh; ./z2.sh > r.txt
Results are in r.txt and look like this for a flat.vmdk with spaces in the name:
_________________________________________________________________________________________________
4195972 /vmfs/volumes/8tb-vmfs6/crazy fox/crazy fox-flat.vmdk
16777216 /vmfs/volumes/8tb-vmfs6/crazy fox/crazy fox-flat.vmdk
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
000001c0 02 00 ee ff ff ff 01 00 00 00 ff ff ff 01 00 00 |................|
000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
00000200 45 46 49 20 50 41 52 54 00 00 01 00 5c 00 00 00 |EFI PART....\...|
00000210 a4 36 e2 71 00 00 00 00 01 00 00 00 00 00 00 00 |.6.q............|
00000220 ff ff ff 01 00 00 00 00 22 00 00 00 00 00 00 00 |........".......|
00000230 de ff ff 01 00 00 00 00 08 a3 7c cc 83 20 58 44 |..........|.. XD|
00000240 a5 08 8b d5 6a 2f 08 b8 02 00 00 00 00 00 00 00 |....j/..........|
00000250 80 00 00 00 80 00 00 00 00 50 8b 4c 00 00 00 00 |.........P.L....|
00000260 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000400
Mapping for file /vmfs/volumes/8tb-vmfs6/crazy fox/crazy fox-flat.vmdk (17179869184 bytes in size):
[ 0: 3145728] --> [VMFS -- LVID:5e0b1f30-249603b4-1451-000c293dfe98/5e0b1f30-1f8acc74-8a00-000c293dfe98/1:( 6067733921792 --> 6067737067520)]
[ 3145728: 2097152] --> [VMFS Z- LVID:5e0b1f30-249603b4-1451-000c293dfe98/5e0b1f30-1f8acc74-8a00-000c293dfe98/1:( 6067737067520 --> 6067739164672)]
[ 5242880: 1048576] --> [VMFS -- LVID:5e0b1f30-249603b4-1451-000c293dfe98/5e0b1f30-1f8acc74-8a00-000c293dfe98/1:( 6067739164672 --> 6067740213248)]
[ 6291456: 61865984] --> [VMFS Z- LVID:5e0b1f30-249603b4-1451-000c293dfe98/5e0b1f30-1f8acc74-8a00-000c293dfe98/1:( 6067740213248 --> 6067802079232)]
[ 68157440: 1048576] --> [VMFS -- LVID:5e0b1f30-249603b4-1451-000c293dfe98/5e0b1f30-1f8acc74-8a00-000c293dfe98/1:( 6067802079232 --> 6067803127808)]
Lock [type 10c00001 offset 202711040 v 92, hb offset 3538944
gen 585, mode 0, owner 00000000-00000000-0000-000000000000 mtime 32168
num 0 gblnum 0 gblgen 0 gblbrk 0]
Addr <4, 26, 1>, gen 4, links 1, type reg, flags 0x2, uid 0, gid 0, mode 600
len 17179869184, nb 16384 tbz 16374, cow 0, newSinceEpoch 16384, zla 3, bs 1048576
affinityFD <4,34,0>, parentFD <4,34,0>, tbzGranularityShift 20, numLFB 32
lastSFBClusterNum 0, numPreAllocBlocks 0, numPointerBlocks 2
OBJLIB-LIB: ObjLib cleanup done.
WORKER: asyncOps=0 maxActiveOps=0 maxPending=0 maxCompleted=0
Ok, I had the time to reproduce this, and understand the issue now (I think).
I did some modifications to your script, so that it doesn't need temporary files, and can also handle datastore names with spaces.
#/bin/sh
cd /vmfs/volumes/
ls -Ap | grep -v / | while read dsName
do
find "/vmfs/volumes/$dsName/" -iname '*-flat.vmdk' | while read fileName
do
echo _________________________________________________________________________________________________
ls -i "$fileName"
ls -s "$fileName"
hexdump -n 1024 -C "$fileName"
echo " "
vmkfstools -p 0 "$fileName" | grep Mapping -A5
echo " "
echo " "
vmkfstools -D -v10 "$fileName"
echo " "
echo " "
done
done
André
Hi Andre
when I saw your modifications I had a lot of fun.
So that is the difference between scripts done by a creative musician and a skilled proffesional ...
Now the ugly hack turns into an elegant solution.
Thank you very much.
May I ask you for help again when / if I manage to figure out the complete thing that I have in mind ?
Ulli
edit: one small feature request ...
The output of the script can become very large with lots of datastores and lots of VMs.
How would I pipe the results into one file for each datastore ?
If possible pipe results into a file for each datastore $dsname-lockinfo.txt
or even better for each flat.vmdk - maybe to /tmp/lockinfo/$dsname/$fileName.txt
Thanks
Hi Ulli,
here's a modified version, which redirects the output to individual files in $OUTDIR.
The file names contain the datastore name, folder name, and file name to allow for same file names in different folders.
For the file names, I've replaced slashes with "__", and spaces with "_b_".
Note that the inner for loop is just a workaround, so that the while read fileName subshell's local variables can be used to redirect the complete loop's output, rather than redirecting each command separately.
#!/bin/sh
OUTDIR="/tmp/lockinfo"
mkdir -p "$OUTDIR" 2> /dev/null
cd /vmfs/volumes/
ls -Ap | grep -v / | while read dsName; do
find "/vmfs/volumes/$dsName/" -iname '*-flat.vmdk' | while read fileName; do
OUTFILE=$(echo "$fileName.txt" | cut -d "/" -f 4- | sed 's/\//__/g' | sed 's/ /_b_/g')
for i in 1; do
ls -i "$fileName"
ls -s "$fileName"
printf -- '-%.0s' $(seq 100); echo -e "\n"
hexdump -n 1024 -C "$fileName"
printf -- '-%.0s' $(seq 100); echo -e "\n"
vmkfstools -p 0 "$fileName" | grep Mapping -A5
printf -- '-%.0s' $(seq 100); echo -e "\n"
vmkfstools -D -v10 "$fileName"
printf -- '-%.0s' $(seq 100); echo -e "\n"
done > "$OUTDIR/$OUTFILE" 2>&1
echo "Done with [$OUTDIR/$OUTFILE]"
done
done
You've got my email address, and phone number, so please feel free to contact me if you want/need help.
André