Created
May 3, 2013 15:13
-
-
Save gizmomogwai/5509735 to your computer and use it in GitHub Desktop.
Clone a stopped VMWare vm.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from = ARGV[0] | |
to = ARGV[1] | |
puts "copy from #{from} to #{to}" | |
def run(cmd) | |
puts "Executing #{cmd}" | |
if !system(cmd) | |
raise "error while executing #{cmd}" | |
end | |
end | |
run("cp -r \"#{from}\" \"#{to}\"") | |
Dir.glob("#{to}/*").each do |f| | |
if f.index(from) | |
new_name = f.gsub(from, to) | |
run("mv \"#{f}\" \"#{new_name}\"") | |
end | |
end | |
def replace_vm_name(filename, from, to) | |
original_content = File.read(filename) | |
new_content = original_content.gsub(from, to) | |
File.write(filename, new_content) | |
end | |
replace_vm_name("#{to}/#{to}.vmx", from, to) | |
replace_vm_name("#{to}/#{to}.vmdk", from, to) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment