Good morning all,
I'm very new to writing perl scripts and need some help please.
I'm scripting the shutting down of a vm, copying files and then exporting the vmdk files over to an ext3 directory. the plan is to have a directory created based on the date and run the script daily.
Here's the problem:
`vmkfstools -i \vmfs3_file_path\server\server.vmdk -d 2gbsparse \ext3_path\[b]$date[/b]\server.vmdk`;
Where $date produces 20070619 (or a new date everyday). Of course, when I hardcode 20070619 in the export - it works...but, I can't seem to "plug-in" the variable $date.
I've tried to make an assignmnt $dest = "\ext3_path\$date\server.vmdk"';
do a print on $dest and it looks good.
and then run
`vmkfstools -i \vmfs3_file_path\server\server.vmdk -d 2gbsparse $dest`;
but it doesn't work:
Failed to clone disk : the file already exist. (39)
Permission denied.
I know it has something to do with how I'm defining variables (and what can be syntactically allowed). My knowledge of Perl and Linux scripting is very limited but, I learning. Can anyone help? thanks, tom
ESX 3.01
Hello,
A few things first. Paths use / not \ to represent changes in directories. Without seeing the 'perl' script it would be hard to debug completely. Also, spaces/special characters in filenames, vm names are hard to handle. Hence the use of quotes in the vmkfstools command.
Here is a 'shell script' not perl that should work for you.
#!/bin/bash
$dm=`date +"%m%d%y"`
if \[ ! -e /ext3path/$dm/server ]
then
mkdir -p /ext3path/$dm/server
fi
if \[ ! -e /ext3path/$dm/server.vmdk ]
then
vmkfstools -i "/vmfs/volumes/SANVolumeName/server/server.vmdk" -d 2gbsparse "/ext3path/$dm/server/server.vmdk"
fi
Best regards,
Edward
Thank you for the response Edward.
oh yeah, it is coded as / forward slash.
I'm definitely thinking that it has something to do with special characters and syntax.
If I print to the screen/file the variable I get the path results on two[/u] separate lines:
/mnt/usb/server/20070619
/server.vmdk
maybe a special char after the $date variable: $newdir = "/mnt/usb/server/$date";
I'll continue to try different things out.
Thanks, tom
Hello,
Does the 'script' I gave work?
It looks like $date has a newline in it at the very least. Use 'vi -b fileName' the -b will show all ctrl-M's etc. The other option is to post the salient bits of code.
Best regards,
Edward
Good morning Edward and all,
your script is close to what I have though I was using perl.
I did vi - b the file and did not see any cntl-M's.
But, what did work...as per your hint at special character being appended to variables was using chomp.
So it looks like this:
#! /usr/bin/perl -w
my $datedir = `date +%Y%m%d`;
chomp $datedir;
so then I was able to make a dir variable that used $datedir[/u]
and then perform the vmkfstools -i (export) source.server.vmdk to dest_vmdk/[u]$datedir[/u]/server.vmdk
It was the /n character at the end of $datedir. Inexperienced in perl, rusty programming skills, information overload -whether to use shell commands or perl commands, all were my problems. Thank you for pointing me in the right direction I appreciate it. I picked up a perl book yesterday after work! Thanks, tom