I've got a two line shell script to take a snapshot of a virtual machine. The script works and a snapshot is taken with the correct name and description using the vmware-cmd command. But I get an error as if the script is trying to execute two parts of the same line.
CODE
#!/bin/sh
`vmware-cmd /vmfs/volumes/Storage1/roadrunner.cooper.local/roadrunner.cooper.local.vmx createsnapshot "_BackupShot_" "Snapshot for Backups" 1 0`
OUTPUT
./backup.sh: line 3: createsnapshot(_BackupShot_,: command not found
I'm no expert at shell script but I can't understand why this error is occuring when the command executes perfectly!
Thanks for any help!
Would I then use the backtick?
In this case yes, or you can also use:
variable=$(command line)
Andre
Remove the backtick (char ` ) from the beginning and the end of the line.
Andre
How about if I want to output of that command to go into a varitable?
snapshop = `vmware-cmd /vmfs/volumes/Storage1/roadrunner.cooper.local/roadrunner.cooper.local.vmx createsnapshot "_BackupShot_" "Snapshot for Backups" 1 0`
Would I then use the backtick?
Thanks for your help!
Would I then use the backtick?
In this case yes, or you can also use:
variable=$(command line)
Andre
You can use either back ticks or $() to embed your command as described.
Try this:
#!/bin/bash my_output=$(vmware-cmd /vmfs/volumes/Storage1/roadrunner.cooper.local/roadrunner.cooper.local.vmx createsnapshot "BackupShot" "Snapshot for Backups" 1 0)
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".