Jeremy Weisinger
asked on
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=8D856799624C44ADA6 890EC652B1 5941
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=8D856799624C44ADA6 890EC652B1 5941
C:\WINDOWS\system32>FOR /F "usebackq delims==" %x IN (`rsm view /tphysical_media /cg8D856799624C44ADA6890EC 652B15941 /guiddisplay /b`) DO set tapeguid=%x
C:\WINDOWS\system32>set tapeguid=6382E4A892CE41ACB A4FC105D42 A467F
C:\WINDOWS\system32> ::continues executing script without issue::
Output when not working:
C:\WINDOWS\system32>Set drvguid=8D856799624C44ADA6 890EC652B1 5941
C:\WINDOWS\system32>FOR /F "usebackq delims==" %x IN (`rsm view /tphysical_media /cg8D856799624C44ADA6890EC 652B15941 /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.
Lines of relevant code:
Set drvguid=8D856799624C44ADA6
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=8D856799624C44ADA6
C:\WINDOWS\system32>FOR /F "usebackq delims==" %x IN (`rsm view /tphysical_media /cg8D856799624C44ADA6890EC
C:\WINDOWS\system32>set tapeguid=6382E4A892CE41ACB
C:\WINDOWS\system32> ::continues executing script without issue::
Output when not working:
C:\WINDOWS\system32>Set drvguid=8D856799624C44ADA6
C:\WINDOWS\system32>FOR /F "usebackq delims==" %x IN (`rsm view /tphysical_media /cg8D856799624C44ADA6890EC
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
I'll keep an eye on the script of course but I think I can close this question. Thanks for the troubleshooting steps!
ASKER
Thanks!