Skip to content

Instantly share code, notes, and snippets.

@miticojo
Last active June 16, 2016 05:37
Show Gist options
  • Save miticojo/d6c8b1345770cd66942171958f7f9a04 to your computer and use it in GitHub Desktop.
Save miticojo/d6c8b1345770cd66942171958f7f9a04 to your computer and use it in GitHub Desktop.
This script convert VMX+VMDK native machine to OVA file
#!/bin/bash
## Author: Giorgio Crivellari <miticojo>
## Description: This script convert VMX+VMDK native machine to OVA file
## Date: April 1, 2016
## More info about OVFTOOL: https://www.vmware.com/support/developer/ovf/ovf410/ovftool-410_userguide.pdf
VMNAME=$1
BASEDIR=/data
if [ ! -f $BASEDIR/$VMNAME/$VMNAME.vmx ]; then
echo "VM not found" 1>&2
exit 2
fi
echo "Starting conversion of VM $VMNAME ..."
ovftool $BASEDIR/$VMNAME/$VMNAME.vmx $BASEDIR/OVA/$VMNAME.ova > $BASEDIR/$VMNAME/ova.log 2>&1 &
echo "... process started in background and it can be monitored in log file:"
echo $BASEDIR/$VMNAME/ova.log
echo ".... at the end of conversion your $VMNAME.ova will be available here:"
echo $BASEDIR/OVA/$VMNAME.ova
exit 0
#!/bin/bash
## Author: Giorgio Crivellari <miticojo>
## Description: This script loop all VMX file, check that no file are locked by vsftpd and run convert_ova.sh script
## Can be used in cron to auto-create OVA file for any uploaded VM
## Date: April 1, 2016
BASEDIR=/data
CONVERTCMD=/root/convert_ova.sh
THRESHOLD_SPACE=90
if [ "$(df -k $BASEDIR | grep "/" | cut -d" " -f 6 | tr -d '%')" -gt $THRESHOLD_SPACE ]; then
echo "Not enough space left on device"
exit 2
fi
for VMX in $BASEDIR/*/*.vmx; do
VMNAME=$(basename "${VMX%%.*}")
LOCK=$(lsof $BASEDIR/$VMNAME/* | grep vsftpd | wc -l)
if [ ! -f $BASEDIR/OVA/$VMNAME.ova ] && [ $LOCK -eq 0 ]; then
$CONVERTCMD $VMNAME 2>&1 | logger &
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment