# [EMAIL PROTECTED] / 2002-11-21 02:17:13 -0500:
> Following the suggestions that were posted, I now have a working 
> script that checks for a connection to the DVD-RAM drive. The 
> following works, but returns the 'Device not configured' error 
> if there's no disk in the drive.
> 
>         elif !(sudo mount -t ufs -o rw /dev/cd0a $montering_punkt)
>         then
> 
> Currently, I'm suppressing the error message (2>/dev/null), but I'd 
> rather capture sterr in a variable and replace it with a custom 
> message if the error is 'Device not configured'. (The devise is 
> configured, but I forgot to put a disk in the drive, so the system 
> error message is confusing.) I've tried read and redirection, but I 
> can't seem to capture the error message in a variable. Does 
> anyone know how to do this?

    tested in zsh (should work in bash):

    MSG=$(sudo mount ... 2>&1)
    if [ $? -ne 0 -a $MSG == "Device not configured" ]; then
        echo "My custom error message"
    fi

    a dumbed-down version that'll work in /bin/sh (most portable):

    MSG=`sudo mount /floppy 2>&1`
    if [ $? -ne 0 -a "x$MSG" = "xDevice not configured" ]; then
        echo "My custom error message."
    fi

-- 
If you cc me or remove the list(s) completely I'll most likely ignore
your message.    see http://www.eyrie.org./~eagle/faqs/questions.html

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message

Reply via email to