Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Nov 2002 10:41:13 +0100
From:      Roman Neuhauser <neuhauser@bellavista.cz>
To:        FreeBSD Questions List <freebsd-questions@freebsd.org>
Subject:   Re: Bash programming; Was: connecting to SCSI drive
Message-ID:  <20021121094112.GR77198@freepuppy.bellavista.cz>
In-Reply-To: <20021121071713.GA2641@sten.alder.net>
References:  <20021120180314.GA564@sten.alder.net> <20021120182423.GB30909@dan.emsphone.com> <3DDBE4A9.5060708@mac.com> <20021120204738.GA949@sten.alder.net> <20021121071713.GA2641@sten.alder.net>

next in thread | previous in thread | raw e-mail | index | archive | help
# rjhalljr@starpower.net / 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 majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021121094112.GR77198>