Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check tape loaded script

Status
Not open for further replies.

bilbonvidia

Technical User
Feb 6, 2007
131
GB
Is it possible to write a simple DOS script that will check if a backup tape is loaded and perform an action if not.

I was thinking it will involve an IF statement using the rsm command (removable storage manager command) ?
 
While this is for Windows 2003, see if my old thread thread931-655160 helps.
 
Hi. Thanks for your help. I am trying unsuccessfully to get the below working can you see anything wrong?

C:\Documents and Settings\Administrator>FOR /F "usebackq delims==" %%i IN (`rsm
view /tphysical_media /cg%drvguid% /guiddisplay /b`) DO set tapeguid=%%i
%%i was unexpected at this time.

The %drvguid% is set correctly.
 
When typing at a command-line, use only 1 percent-sign (%) for variable names. The double percent-sign is only required in a batch file.
 
Can you see why the below would fail, it works if there is a tape in the drive and I get told but it just seems to bomb if there is no tape?

FOR /F "usebackq delims==" %%i IN (`rsm view /tphysical_media /cg189167B52A3D4084A647D62224484771 /guiddisplay /b`) DO set tapeguid=%%i
if %tapeguid%=="" GOTO NOTAPE
GOTO END

:NOTAPE


NET SEND IOM189 NO TAPE

It doesn't seem to like the "if %tapeguid%=="" when there is no tapeguid variable set.

:END
net send iom189 tape

 
ignore the end bit of that code as its wrong, but why doesn't my dos seem to like

if %tapeguid%=="" when there is not tapguid variable due to there being no tape in the drive?

Thanks for your help.
 
OK Changed it to this:
if '%tapeguid%'=='' GOTO NOTAPE

Now working! How come?
 
I am not happy with the IF %tapeguid% statement so using this instead

FOR /F "usebackq delims==" %%i IN (`rsm view /tphysical_media /cg189167B52A3D4084A647D62224484771 /guiddisplay /b`) DO set tapeguid=%%i
set > z:\temp\set.txt

FIND /I "tapeguid" Z:\TEMP\SET.TXT
IF ERRORLEVEL 1 GOTO NOTAPE

 
Sorry it took me a few days to get back. I've never looked in to it fully, but the command environment is kind of weird when dealing with variables. Probably stems from the fact that you can create them on the fly. When you use a variable for the first time it has no value whatsoever (basically NULL). It's not even equal to the empty string "". In my earlier thread you'll notice a line that reads
set tapeguid=""
That line assures that tapeguid will have some value, even if it's only the empty string.

If the RSM VIEW command finds a tape, it assigns that GUID to tapeguid so the variable is no longer empty. If RSM VIEW does not return a GUID, then tapeguid is not changed at all and would have whatever value it had prior to the RSM VIEW statement. If you never assign it an initial value, then it is essentially NULL, and NULL is not equal to "". That's why that line was failing. I'm glad you found a work-around though.
 
Thanks for the reply. Yes I see what you mean, now that I see set tapeguid="" is should have been blindingly obvious why it was failing.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top