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

LVL 24
Jeremy WeisingerSenior Network Consultant / EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Storage

From novice to tech pro — start learning today.