LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 07-21-2004, 12:42 PM   #1
Finlay
Senior Member
 
Registered: Mar 2003
Location: Seattle
Distribution: Slackware ?-14.1
Posts: 1,029

Rep: Reputation: 47
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?
 
Old 07-21-2004, 02:39 PM   #2
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Rep: Reputation: 32
I wouldn't do the
Code:
mt -f /dev/st0 rewind
becuase it will rewind the tape if it is in there (unless that's what you want to do.
Is that what you want to do? (That will make things easier if it is).
 
Old 07-21-2004, 02:52 PM   #3
SheldonPlankton
Member
 
Registered: Jun 2004
Posts: 129

Rep: Reputation: 15
Sounds like you could easily write a Perl script to do this ...
Code:
...
my $mtCmd = "/bin/mt -f /dev/st0 status";
open( MT, "|$mtCmd" ) or die "Can't do $mtCmd:$!\n";

# if last line of output is  DR_OPEN IM_REP_EN send me email
...
You could even write a shell script to do this.
Code:
grep DR_OPEN `/bin/mt -f /dev/st0 status|tail -1`

if [ $? != 0 ]
then
    mail -S "No Tape" ....
fi
 
Old 07-21-2004, 05:27 PM   #4
Finlay
Senior Member
 
Registered: Mar 2003
Location: Seattle
Distribution: Slackware ?-14.1
Posts: 1,029

Original Poster
Rep: Reputation: 47
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
 
Old 07-21-2004, 05:37 PM   #5
mossy
Member
 
Registered: Aug 2003
Location: USexIRL
Distribution: *nix
Posts: 849

Rep: Reputation: 30


<EDIT>


Oops - nevermind I see you already got past that - double check your locations and run as root?

</EDIT>

Last edited by mossy; 07-21-2004 at 05:43 PM.
 
Old 07-21-2004, 05:42 PM   #6
Finlay
Senior Member
 
Registered: Mar 2003
Location: Seattle
Distribution: Slackware ?-14.1
Posts: 1,029

Original Poster
Rep: Reputation: 47
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
 
Old 07-21-2004, 05:47 PM   #7
mossy
Member
 
Registered: Aug 2003
Location: USexIRL
Distribution: *nix
Posts: 849

Rep: Reputation: 30
where's it getting the reference for ' BOT ONLINE IM_REP_EN' in that script?
 
Old 07-21-2004, 06:04 PM   #8
Finlay
Senior Member
 
Registered: Mar 2003
Location: Seattle
Distribution: Slackware ?-14.1
Posts: 1,029

Original Poster
Rep: Reputation: 47
BOT ONLINE IM_REP_EN is the result of
mt -f /dev/st0 status|tail -1
when there is a tape in the drive
 
Old 07-21-2004, 11:34 PM   #9
SheldonPlankton
Member
 
Registered: Jun 2004
Posts: 129

Rep: Reputation: 15
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

Heck you could probably even do something like this ...

/bin/mt -f /dev/st0 status > /dev/null 2>&1
if [ $? != 0 ]
then
mail
fi


Last edited by SheldonPlankton; 07-22-2004 at 12:00 AM.
 
Old 07-22-2004, 02:57 PM   #10
Finlay
Senior Member
 
Registered: Mar 2003
Location: Seattle
Distribution: Slackware ?-14.1
Posts: 1,029

Original Poster
Rep: Reputation: 47
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
 
Old 07-22-2004, 05:03 PM   #11
mossy
Member
 
Registered: Aug 2003
Location: USexIRL
Distribution: *nix
Posts: 849

Rep: Reputation: 30
replace
Code:
if [ $? != 0 ]
with
Code:
if [ $? = 0 ]
and giver a whirl
 
Old 07-22-2004, 06:02 PM   #12
Finlay
Senior Member
 
Registered: Mar 2003
Location: Seattle
Distribution: Slackware ?-14.1
Posts: 1,029

Original Poster
Rep: Reputation: 47
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?
 
Old 07-22-2004, 06:09 PM   #13
SheldonPlankton
Member
 
Registered: Jun 2004
Posts: 129

Rep: Reputation: 15
Use a here doc ...
Code:
$ mail -s "test test" dogface <<EOT
> Hi
> there how are things
> this is call a "Here document" in shell scripting
> EOT
bash-2.05b$ mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/dogface": 1 message 1 new
>N  1 dogface@localh  Thu Jul 22 15:04  18/794   "test test"
& 1
Message 1:
From dogface@localhost.localdomain  Thu Jul 22 15:04:30 2004
Date: Thu, 22 Jul 2004 15:04:29 -0700
From: Dogface Monkey <dogface@localhost.localdomain>
To: dogface@localhost.localdomain
Subject: test test
 
Hi
there how are things
this is call a "Here document" in shell scripting
 
& q
Saved 1 message in mbox
To do the above in your script your script should have lines in it that look like this ...
Code:
mail -s "test test" Finlay <<EOT
Hi there,
how are things?

this is call a "Here document" in shell scripting
EOT
 
Old 07-22-2004, 08:02 PM   #14
Finlay
Senior Member
 
Registered: Mar 2003
Location: Seattle
Distribution: Slackware ?-14.1
Posts: 1,029

Original Poster
Rep: Reputation: 47
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?
 
Old 07-22-2004, 08:43 PM   #15
mossy
Member
 
Registered: Aug 2003
Location: USexIRL
Distribution: *nix
Posts: 849

Rep: Reputation: 30
try adding the -u parameter to mail:
Code:
mail -su uid_finley "test test" Finlay <<EOT
not sure if this is correct usage it may be:
Code:
mail -s "test test" -u uid_finley Finlay <<EOT
you may also need to setup smtp server settings etc - but I am not sure.

Last edited by mossy; 07-22-2004 at 08:49 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Floppy drive interfaced tape drive in Slackware isolationist Linux - Hardware 6 02-13-2006 06:54 AM
Simple shell script query sachinh Programming 5 09-07-2005 05:02 AM
Send query string via MIRC script cadj Programming 0 08-25-2004 07:25 AM
Speeding up the script, or the SQL Query? knickers Programming 1 04-13-2004 12:57 PM
Query about script variable phantomdude Linux - Newbie 1 03-18-2004 12:21 PM


All times are GMT -5. The time now is 06:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration