need script to query tape drive
I want to run a script each day to query a tape drive to see if there is a tape in it.
If there isn't a tape in it i want an email sent to notify me. (users aren't putting the tapes in everyday. If i run this when there isn't a tape i get: mt -f /dev/st0 status SCSI 2 tape drive: File number=-1, block number=-1, partition=0. Tape block size 0 bytes. Density code 0x0 (default). Soft error count since last status=0 General status bits on (50000): DR_OPEN IM_REP_EN If i run this when there is a tape in the drive i get: mt -f /dev/st0 status SCSI 2 tape drive: File number=0, block number=0, partition=0. Tape block size 512 bytes. Density code 0x48 (Quantum SDLT220). Soft error count since last status=0 General status bits on (41010000): BOT ONLINE IM_REP_EN If i run this with a tape in i get nothing back: mt -f /dev/st0 rewind If i run this when there isn't a tape in the drive i get: mt -f /dev/st0 rewind /dev/st0: No medium found mt: The device is offline (not powered on, no tape ?). Is there a way to take any of these outputs and use them to send an email when there isn't a tape in? |
I wouldn't do the
Code:
mt -f /dev/st0 rewind Is that what you want to do? (That will make things easier if it is). |
Sounds like you could easily write a Perl script to do this ...
Code:
... Code:
grep DR_OPEN `/bin/mt -f /dev/st0 status|tail -1` |
since i don't know anything about perl the shell script would be best, but i get the following error when i run:
grep DR_OPEN `/bin/mt -f /dev/st0 status|tail -1` if [ $? != 0 ] then mail -s 'No Tape' finlay@finlay.homelinux.org fi grep: BOT: No such file or directory grep: ONLINE: No such file or directory grep: IM_REP_EN: No such file or directory then it halts on the mail part and i have to ctrl-c it twice |
<EDIT> Oops - nevermind I see you already got past that - double check your locations and run as root? </EDIT> |
ok here is what i got:
#!/bin/bash grep DR_OPEN `/bin/mt -f /dev/st0 status|tail -1` if [ $? != 0 ] then mail -s 'No Tape' finlay@finlay.homelinux.org fi and this is what i get: grep: BOT: No such file or directory grep: ONLINE: No such file or directory grep: IM_REP_EN: No such file or directory |
where's it getting the reference for ' BOT ONLINE IM_REP_EN' in that script?
|
BOT ONLINE IM_REP_EN is the result of
mt -f /dev/st0 status|tail -1 when there is a tape in the drive |
Oops! I meant
/bin/mt -f /dev/st0 status|tail -1| grep DR_OPEN I think ... my point was you can write a shell script to do what you want. I didn't bother testing any code I posted. Sorry :D Heck you could probably even do something like this ... /bin/mt -f /dev/st0 status > /dev/null 2>&1 if [ $? != 0 ] then fi |
Ok this is what i have now:
#!/bin/bash /bin/mt -f /dev/st0 status|tail -1| grep DR_OPEN if [ $? != 0 ] then mail -s 'No Tape' finlay@finlay.homelinux.org fi The problem is it is trying to send mail when the tape is in, not when it is out. And it is still halting at the mail command |
replace
Code:
if [ $? != 0 ] Code:
if [ $? = 0 ] |
thanks mossy, the script works to the point of the mail command.
It keeps wanting user intervention to actually send the email. Do you know of any switches that will send the email, or if you can > it to an attachment? |
Use a here doc ...
Code:
$ mail -s "test test" dogface <<EOT Code:
mail -s "test test" Finlay <<EOT |
that worked to send to a local user.
when i tried to send it to an external address it got rejected because it came from root@localhost.localdomain is there a way to set a from or reply to address? |
try adding the -u parameter to mail:
Code:
mail -su uid_finley "test test" Finlay <<EOT Code:
mail -s "test test" -u uid_finley Finlay <<EOT |
All times are GMT -5. The time now is 05:23 PM. |