Hi all,
I'm new to bash scripting and have a little problem with the following script:
if [ $# -ne 0 ] && [ -d /vmware/$1 ]
then
vmxFile=`find /vmware/$1 -name "*.vmx"`
else
echo "Directory does not exist."
exit 1
fi
cd /scripts
./PowerOff.pl $1 $vmxFile
sleep 10
tar -cvzf $1.tgz /vmware/$1
if [ $? -eq 0 ]
then
if [ -e $1.tgz ]
then
lftp -c put $1.tgz -o
ftp://10.11.71.25/VMwareBackups/
if [ $? -eq 0 ]
then
send_mail $1 "`hostname`: Backup Virtual Machine Successful"
rm $1.tgz
./PowerOn.pl $1 $vmxFile
else
send_mail $1 "`hostname`: Backup Virtual Machine Failed"
fi
fi
else
send_mail $1 "`hostname`: Backup Virtual Machine Failed"
fi
When i run the script the find command retrieves the name of the VMX file from the virtual machine to be stopped, and puts the name in the vmxFile string. The string contains spaces and when i pass string vmxFile as an argument to ./PowerOff.pl it treats the string like several small arguments instead of one big argument, causing ./PowerOff.pl to crash.
How can i accomplish that the string will be seen as one argument instead of several small ones?
Any help will be appreciated.
TIA