Re: bash script stop/continue depending on caddy state.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/9/07, Jacques B. <jjrboucher@xxxxxxxxx> wrote:
> On 10/8/07, Strong <strong_yethumble@xxxxxxxxx> wrote:
> > I have a bash script that works with a cdrom drive. And a have a point
> > where the script should automaticly eject the caddy and then wait for
> > user to load it with another cd, then the script continues its work.
> >
> > I realised it by eject command to unload caddy, then wait for a key hit
> > with 'read' then it 'eject -t' to close the caddy then the script
> > continues.
> >
> > What I want is to remove the key hitting but replace it with caddy load
> > instead - just script stops when the caddy has been ejected and
> > continues after caddy has been closed (with the help of an user).
> >
> > Any suggestions?
>
> I'd be interested in seeing that part of the script (the eject).  I
> have never played with that command.  Is it a bash command or an
> external command?
>
> Regards how to detect the caddy being loaded, I haven't tested but
> someone else may have.  Are there any logs that get populated when you
> load a CD into a caddy?  If so your script could monitor that log
> using a loop of sorts (perhaps with a pause in the loop so it's not
> chewing up too many cycles).  When the appropriate log activity is
> noted the script breaks out of the loop.  I'd include a safeguard such
> as a counter in the loop that if Max_Count was reached to exit the
> loop and prompt the user to select either Abort or OK depending on if
> they wished to abort the script, or that OK the CD is loaded but was
> not detected (or not loaded in the initial delay period set in the
> loop).
>
> Jacques B.
>
I wasn't sitting at my linux box this morning, and given it wasn't
even 6:00 am my brain was still asleep.  I found the eject command
(that was easy...).

Regards detecting the loading of a CD, how about the output of the
mount command?  Once automounted you will see it in the ouput of your
mount command.  Just grep for it.  The only caveat is the script will
have to be modified for different systems (given the CD could be
assigned a different device name) both as it relates to hardware
configuration and version of OS since I learned that F7 assigned IDE
devices different /dev/ names than in older versions (not /dev/hdx
anymore).

Alternatively you could enumerate the content of the output of the
mount command or of /proc/mounts and look for CD file systems (I noted
that the "type" for one of the CDs I tried is "iso9660" and has the
read-only flag set).

I do note that with the eject command's verbose option -v you are
provided with what /dev/cdrom relates to (because under the output of
the mount command and in /proc/mounts it uses the actual device name)
so you could parse the device name out of there in order to know what
to monitor for in /proc/mounts for evidence of a re-load.  Again even
easier you can get that from ls -l /dev/cdrom and parse it from the
output.

Of all of them I'd recommend parsing the output of the eject -v
command.  That way you know for certain that you are capturing the
device name of the device you ejected in scenarios where there may be
multiple optical drives in the box.

Jacques B.


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux