VMware Cloud Community
The-Kevster
Contributor
Contributor
Jump to solution

VERY simple shell script driving me mad!!!

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

./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!

0 Kudos
1 Solution

Accepted Solutions
AndreTheGiant
Immortal
Immortal
Jump to solution

Would I then use the backtick?

In this case yes, or you can also use:

variable=$(command line)

Andre

Andrew | http://about.me/amauro | http://vinfrastructure.it/ | @Andrea_Mauro

View solution in original post

0 Kudos
4 Replies
AndreTheGiant
Immortal
Immortal
Jump to solution

Remove the backtick (char ` ) from the beginning and the end of the line.

Andre

Andrew | http://about.me/amauro | http://vinfrastructure.it/ | @Andrea_Mauro
0 Kudos
The-Kevster
Contributor
Contributor
Jump to solution

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!

0 Kudos
AndreTheGiant
Immortal
Immortal
Jump to solution

Would I then use the backtick?

In this case yes, or you can also use:

variable=$(command line)

Andre

Andrew | http://about.me/amauro | http://vinfrastructure.it/ | @Andrea_Mauro
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

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".

0 Kudos