Subscribe

Get and expand the PM_VOLUME_NAME environment variable via Windows batch

Hey everyone.

I want to be able to turn off the array based snapshot schedule on a particular volume once it has been provisioned through Provisioning Manager. Turns out you can use a post provisioning script to do so as long as you can get at the PM_VOLUME_NAME environment variable. Through my travels in the community I have learned there is a PERL way of expanding all of the variables in %ENV. See below:

  foreach $key (sort(keys %ENV))

  {

if ($key =~ /^PM_/) {

print "$key: $ENV{$key}\n";

}

  }

I have also learned the the PM_VOLUME_NAME is returned as filer:/vol/volume.

Here is my script:

@echo off

set vol_name=PM_VOLUME_NAME

for /f "delims=: tokens=1,2" %%a in ("%vol_name%") do dfm run cmd %%a vol options %%b nosnap on

I am missing the Windows batch equivalent of being able to get and expand PM_VOLUME_NAME into vol_name so I can manipulate it in the next line of the script. Anybody have this lying around?

Thanks in advance.

Re: Get and expand the PM_VOLUME_NAME environment variable via Windows batch

Dennis.

Try this:

@echo off

for /f "delims=: tokens=1,2" %%a in ("%PM_VOLUME_NAME%") do set HOST=%%a&set VOLUME=%%b

echo.Host  : %HOST%
echo.Volume: %VOLUME%

dfm run cmd %HOST% vol options %VOLUME% nosnap on

if %errorlevel% 1 echo.error with dfm command

exit 0

It is extremely important that your provisioning script always exits with a return code of zero (0).  Even if your script fails for some reason, you want it to return zero. Any other return code causes the entire provisioning job ro be rolled-back.  Use logging to capture the return status of commands so you can troubleshoot the script later without causing your provisioning job to be rolled-back.

Reid