ghettoVCB icon indicating copy to clipboard operation
ghettoVCB copied to clipboard

syntax error in ghettoVCB.sh script

Open tadeuszjl opened this issue 9 years ago • 17 comments

/vmfs/volumes/b0e7723c-8167fac7/ghettoVCB # sh ghettoVCB-master/ghettoVCB.sh --help ghettoVCB-master/ghettoVCB.sh: line 836: syntax error: Bad substitution

I changed locally bad brackets to if [[ "${PROBLEM_VMS}/${VM_NAME}" != "${PROBLEM_VMS}" ]] ; then but I do not know if this is expected, or the fix is more complex.

Tadeusz

tadeuszjl avatar Jan 08 '16 23:01 tadeuszjl

This is the original code: if [[ "${PROBLEM_VMS/$VM_NAME}" != "$PROBLEM_VMS" ]] ; then

tadeuszjl avatar Jan 08 '16 23:01 tadeuszjl

The backup script seems to work now, but at the end of the log there is more errors:

2016-01-08 23:41:20 -- info: ============================== ghettoVCB LOG END ================================

sh: missing ]]

BTW I used ghetto for at least 3 years, but lost the disk drive, and backup and had to pull out the new version ....

tadeuszjl avatar Jan 08 '16 23:01 tadeuszjl

This affects me too. This seems to be a compatibility problem affecting older busybox versions of sh? I use esxi 4.1... I tried commenting out the lines from 835 - 942 but got the second error "missing ]]" that you mention.

These other users in the forum mention having this problem too, and say that it is necessary to revert to using an older version of ghettoVCB: https://communities.vmware.com/thread/523977?start=0&tstart=0

@tadeuszjl what version of esxi do you run?

bovine avatar Feb 28 '16 18:02 bovine

I guess this commit by @jobscry caused the "Bad substitution" error? 1bf9ddd00ee231c1df4e2e06e90bb6bd9f924b25

bovine avatar Feb 28 '16 18:02 bovine

Hey, Same problem with the last version from github on ESXi 5.0.0 build 3086167.

Patch: https://github.com/drtomasso/ghettoVCB/commit/255dfc5e6ff8df4098ab57088e42de09ce7acfbc

Thanks!

takenek avatar Mar 13 '16 13:03 takenek

same here. ../ghettoVCB/ghettoVCB.sh: line 836: syntax error: Bad substitution

on VMkernel ....com 5.0.0 #1 SMP Release build-469512 Aug 18 2011 18:32:24 x86_64 unknown ghettoVCB.sh has LAST_MODIFIED_DATE=2015_05_06

This was a case of updating ghettoVCB from an long-term working version where I wanted to take advantage of the -m parameter for ad-hoc backups. Back to the old way of messing with a file and list of machines. (That ghettoVCB.sh has no versioning that I can see)

bisi-sysadmin avatar Mar 20 '16 22:03 bisi-sysadmin

Use this patch: https://github.com/drtomasso/ghettoVCB/commit/255dfc5e6ff8df4098ab57088e42de09ce7acfbc

For me working briliant :-)

takenek avatar Mar 20 '16 22:03 takenek

Thanks for writing vghetto. I hope to be able to use it shortly.

I get the same error message: ../ghettoVCB/ghettoVCB.sh: line 836: syntax error: Bad substitution

Compatible bash code should be: if [[ "${PROBLEM_VMS}/${VM_NAME}" != "$PROBLEM_VMS" ]] ; then

Combining "${PROBLEM_VMS/$VM_NAME}" in a single express is ambiguous, for the parser. It's an easy mistake to make.

beginrescueend avatar Apr 22 '16 22:04 beginrescueend

@beginrescueend That is not the intended behavior. Your proposed change does not cause an error on older esxi versions, but it also does not have the intended behavior. See the comments on drtomasso@255dfc5

bovine avatar Apr 22 '16 22:04 bovine

Thanks for the very quick response.

What is the proposed solution for EXSi 4.0, since it won't run there?

We plan to upgrade our guests from ESXi 4.0 to 6.0, but on our older hardware, I currently have to stop this guest and scp files. I was hoping to use ghettoVCB, instead.

Thanks!

From: Jeff Lawson <[email protected]mailto:[email protected]> Reply-To: lamw/ghettoVCB <[email protected]mailto:[email protected]> Date: Friday, April 22, 2016 at 5:43 PM To: lamw/ghettoVCB <[email protected]mailto:[email protected]> Cc: Mike Hoskins <[email protected]mailto:[email protected]>, Mention <[email protected]mailto:[email protected]> Subject: Re: [lamw/ghettoVCB] syntax error in ghettoVCB.sh script (#83)

@beginrescueendhttps://github.com/beginrescueend That is not the intended behavior. Your proposed change does not cause an error on older esxi versions, but it also does not have the intended behavior. See the comments on drtomasso@255dfc5https://github.com/drtomasso/ghettoVCB/commit/255dfc5

You are receiving this because you were mentioned. Reply to this email directly or view it on GitHubhttps://github.com/lamw/ghettoVCB/issues/83#issuecomment-213615121

beginrescueend avatar Apr 22 '16 22:04 beginrescueend

I had the same problem, ghetto on a ESXi 4.1 (busybox 1.9.1) Afetr some google I found this http://www.linuxquestions.org/questions/programming-9/ash-test-is-string-a-contained-in-string-b-671773/ so I changed the code as follow

if [[ "${IGNORE_VM}" -eq 0 ]] && [[ -n "${PROBLEM_VMS}" ]] ; then
            #old 
            # if [[ "${PROBLEM_VMS/$VM_NAME}" != "$PROBLEM_VMS" ]] ; then
            # logger "info" "Ignoring ${VM_NAME} as a problem VM\n"
            # IGNORE_VM=1
            # #A VM ignored due to a problem, should be treated as a failure
            # VM_FAILED=1
            # fi

           #new
    case $PROBLEM_VMS in 
            "$VM_NAME "* |*" $VM_NAME "*|*" $VM_NAME" ) 
            logger "info" "Ignoring ${VM_NAME} as a problem VM\n"
                               IGNORE_VM=1
                               #A VM ignored due to a problem, should be treated as a failure
                               VM_FAILED=1 ;;
            *) echo "$VM_NAME non è in $PROBLEM_VMS" ;;
        esac
fi

I hope this could be helpfull

flaviol avatar May 20 '16 10:05 flaviol

@flaviol: the code is working for 5.0.0 too.

lasat avatar Sep 17 '17 08:09 lasat

@flaviol fixed it on ESXi 4.0

LudovicVanasse avatar Dec 02 '17 18:12 LudovicVanasse

I have the same issue with the current release and esxi 5.0.0

tomaluca95 avatar Aug 09 '18 10:08 tomaluca95

Yippee, my turn to bump into this.

This line:

if [[ "${PROBLEM_VMS/$VM_NAME}" != "$PROBLEM_VMS" ]] ; then

Is roughly equivalent to:

if [[ "${PROBLEM_VMS}" == *"${VM_NAME}"* ]] ; then

The fancy ${a/$b} syntax ("Pattern substitution" in the "Parameter Expansion" pass) is a bit hard to read, and as noted here not supported in older shells, so I would be in favor of replacing it.

Another issue that sprung to mind when reading this is that if the (good VM) VM_NAME is a subset of another (problem) VM's name, this will incorrectly trigger because we are not presently looking for string boundaries. Example:

VM_NAME='debian'
PROBLEM_VMS='debian2 debian3'

if [[ "${PROBLEM_VMS/$VM_NAME}" != "$PROBLEM_VMS" ]] ; then
# if [[ 2 debian3 != \d\e\b\i\a\n\2\ \d\e\b\i\a\n\3 ]] ; then
     # we end up here because of the partial match
     # turning "debian2" into "2"
fi

if [[ "${PROBLEM_VMS}" == *"${VM_NAME}"* ]] ; then
# if [[ debian2 debian3 == *\d\e\b\i\a\n* ]]; then
     # we also end up here because both debian2 and debian3 match *debian*
fi

My suggested fix would be to add spaces around the VM_NAME before the glob stars, to ensure we have a full match on a boundary-separated VM name. Then we will be unable to match on the first and last entries; we can fix that by surrounding PROBLEM_VMS with spaces in the haystack:

PROBLEM_VMS='debian2 debian3'

VM_NAME='debian2'
if [[ " ${PROBLEM_VMS} " == *" ${VM_NAME} "* ]] ; then
# [[  debian2 debian3  == *\ \d\e\b\i\a\n\2\ * ]]
  # This fully matches 'debian2' 
fi

VM_NAME='debian'
if [[ " ${PROBLEM_VMS} " == *" ${VM_NAME} "* ]] ; then
# [[  debian2 debian3  == *\ \d\e\b\i\a\n\ * ]]
  # this does not match.
fi

jokjr avatar Dec 01 '20 12:12 jokjr

@jokjr Thanks for the suggestion. Do you haver a pull request for this change?

lamw avatar Dec 28 '20 01:12 lamw

@lamw I do not. Feel free to integrate it if you find the time. Otherwise I'll try to find time when I am back from vacation.

jokjr avatar Dec 29 '20 00:12 jokjr