[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 670
  • Last Modified:

RSM script sometimes not setting a variable

I recently wrote (er, put together) a script to get the GUID of the tape that is in the tape drive. It worked fine for a week then it failed..... then, without any interaction that I know of, it started working again.

Lines of relevant code:

Set drvguid=8D856799624C44ADA6890EC652B15941
FOR /F "usebackq delims==" %%x IN (`rsm view /tphysical_media /cg%drvguid% /guiddisplay /b`) DO set tapeguid=%%x

Output when working:

C:\WINDOWS\system32>Set drvguid=8D856799624C44ADA6890EC652B15941  
C:\WINDOWS\system32>FOR /F "usebackq delims==" %x IN (`rsm view /tphysical_media /cg8D856799624C44ADA6890EC652B15941 /guiddisplay /b`) DO set tapeguid=%x
C:\WINDOWS\system32>set tapeguid=6382E4A892CE41ACBA4FC105D42A467F
C:\WINDOWS\system32> ::continues executing script without issue::


Output when not working:

C:\WINDOWS\system32>Set drvguid=8D856799624C44ADA6890EC652B15941  
C:\WINDOWS\system32>FOR /F "usebackq delims==" %x IN (`rsm view /tphysical_media /cg8D856799624C44ADA6890EC652B15941 /guiddisplay /b`) DO set tapeguid=%x
C:\WINDOWS\system32> ::goes directly to next line without setting the "tapeguid" variable::


Does anyone know why this happens? Do I need to run a rsm refresh before executing the the rsm view? Any help would be great.

Attached is the full script.
Set drvguid=8D856799624C44ADA6890EC652B15941 
FOR /F "usebackq delims==" %%x IN (`rsm view /tphysical_media /cg%drvguid% /guiddisplay /b`) DO set tapeguid=%%x
FOR /F "usebackq delims==" %%x IN (`rsm view /tpartition /cg%tapeguid% /guiddisplay /b`) DO set partguid=%%x
FOR /F "usebackq delims==" %%x IN (`rsm view /tlogical_media /cg%partguid% /guiddisplay /b`) DO set logguid=%%x
Set part1=%logguid:~0,8%
Set part2=%logguid:~8,4%
Set part3=%logguid:~12,4%
Set part4=%logguid:~16,4%
Set part5=%logguid:~20,12%
Set bkupguid=%part1%-%part2%-%part3%-%part4%-%part5%
 
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\Daily Backup.bks" /n "Daily Backup %date%" /d "Daily Backup %date%" /v:yes /r:no /rs:no /hc:on /m normal /j "Daily Backup" /l:s /g "%bkupguid%"
 
rsm eject /pg%tapeguid% /astart

Open in new window

0
Jeremy Weisinger
Asked:
Jeremy Weisinger
  • 2
1 Solution
 
oBdACommented:
This will happen if the command in the "for" loop doesn't generate any output.
You might want to create a log file, so that you can see what actually went wrong.
The snippet below will run each command twice, the first time just to log the output, the second time in the "for" loop.
The refresh might help.
set LogFile=C:\temp\rsm.log
if exist "%LogFile%" del "%LogFile%"
Set drvguid=8D856799624C44ADA6890EC652B15941
 
>>"LogFile" echo running 'rsm view /tphysical_media /cg%drvguid% /guiddisplay /b'
rsm view /tphysical_media /cg%drvguid% /guiddisplay /b >>"%LogFile%" 2>&1
FOR /F "usebackq delims==" %%x IN (`rsm view /tphysical_media /cg%drvguid% /guiddisplay /b`) DO set tapeguid=%%x
>>"LogFile" echo tapeguid=%tapeguid%
 
>>"LogFile" echo running 'rsm view /tpartition /cg%tapeguid% /guiddisplay /b'
rsm view /tpartition /cg%tapeguid% /guiddisplay /b >>"%LogFile%" 2>&1
FOR /F "usebackq delims==" %%x IN (`rsm view /tpartition /cg%tapeguid% /guiddisplay /b`) DO set partguid=%%x
>>"LogFile" echo partguid=%partguid%
 
>>"LogFile" echo running 'rsm view /tlogical_media /cg%partguid% /guiddisplay /b'
rsm view /tlogical_media /cg%partguid% /guiddisplay /b >>"%LogFile%" 2>&1
FOR /F "usebackq delims==" %%x IN (`rsm view /tlogical_media /cg%partguid% /guiddisplay /b`) DO set logguid=%%x
>>"LogFile" echo logguid=%logguid%

Open in new window

0
 
Jeremy WeisingerSenior Network Consultant / EngineerAuthor Commented:
Excellent idea. I will add the duplicate command. I'm already logging the output. I will test this and see how things run tonight.... of course they may run fine so we'll see.

Thanks!
0
 
Jeremy WeisingerSenior Network Consultant / EngineerAuthor Commented:
Well the command give absolutely no information when it doesn't return the GUID. I suppose I could start looking at the errorlevel and that might give me a clue.... but I put in an IF statement to check if the variable is defined and if it isn't it will try again. So far that has worked. On the second time around it gets the GUID and the script completes successfully.

I'll keep an eye on the script of course but I think I can close this question. Thanks for the troubleshooting steps!
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now