Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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).
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
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
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?
$ 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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.