From owner-freebsd-questions@FreeBSD.ORG Tue Jan 8 22:13:08 2013 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 4C0D2D7B for ; Tue, 8 Jan 2013 22:13:08 +0000 (UTC) (envelope-from fbsd8@a1poweruser.com) Received: from mail-03.name-services.com (mail-03.name-services.com [69.64.155.195]) by mx1.freebsd.org (Postfix) with ESMTP id 0B6FFEC3 for ; Tue, 8 Jan 2013 22:13:07 +0000 (UTC) Received: from [10.0.10.3] ([173.88.197.103]) by mail-03.name-services.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 8 Jan 2013 14:13:08 -0800 Message-ID: <50EC99F2.3020404@a1poweruser.com> Date: Tue, 08 Jan 2013 17:13:06 -0500 From: Fbsd8 User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: Polytropon Subject: Re: sh script problem with capturing return code References: <50EC9009.3030305@a1poweruser.com> <20130108224626.8c2d89cd.freebsd@edvax.de> In-Reply-To: <20130108224626.8c2d89cd.freebsd@edvax.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 08 Jan 2013 22:13:09.0028 (UTC) FILETIME=[573D4E40:01CDEDED] X-Sender: fbsd8@a1poweruser.com X-Authenticated-Sender: fbsd8@a1poweruser.com X-EchoSenderHash: [fbsd8]-[a1poweruser*com] Cc: FreeBSD questions X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Jan 2013 22:13:08 -0000 Polytropon wrote: > On Tue, 08 Jan 2013 16:30:49 -0500, Fbsd8 wrote: >> I can not get the return code from mtree to control >> the displaying of a error message. >> >> The mtree at the end of the script does function correctly >> because I can tell from the printed output. >> >> When mtree prints comments saying "extra" that means the directory being >> read does not match the specification file. return code should be Not >> equal to zero. >> >> And when they do match IE: no mtree comments printed, that should be a >> return code of zero. >> >> I tried 2 different ways to capture the return code to no joy. >> What I am doing wrong? >> >> #! /bin/sh >> flavor="/a/mtree.std" >> echo "flavor = ${flavor}" >> /bin/cat << EOF | >> /set type=dir uname=root gname=wheel >> . >> etc ignore >> .. >> root ignore >> .. >> usr >> home ignore >> .. >> local >> etc ignore >> .. >> .. >> .. >> .. >> EOF >> >> mtree -d -u -p "${flavor}" || \ >> echo "Error invalid directories in flavor ${flavor}." >> >> #mtree -d -p "${flavor}" >> #[ $? -eq 0 ] || \ >> # echo "Error invalid directories in flavor ${flavor}." >> echo "return = $?" > > It seems that returning 0 is correct in a case as you mentioned. > The manual at "man mtree" states: > > EXIT STATUS > The mtree utility exits 0 on success, and >0 if an error occurs. > > Question: What _is_ an error here? > > If you use the source Luke at /usr/src/usr.sbin/mtree/mtree.c, > you could find out what combination of options plus circumstances > found at runtime could trigger an exit status != 0. > > The main() functions finishes with exit(status); where status > is either set by functions mtree_specspec() or mtree_verifyspec(), > or manually to 0 when -U is provided and MISMATCHEXIT (is 2) is > encountered. > > Again from the manual: > > -u Same as -U except a status of 2 is returned if the file hierarchy > did not match the specification. > > -U Modify the owner, group, permissions, and modification time of > existing files to match the specification and create any missing > directories or symbolic links. User, group and permissions must > all be specified for missing directories to be created. Corrected > mismatches are not considered errors. > > However, you're not using -U, but -u, so the last sentence of > the description above should be relevant: No error per se, > even though the status code should be 2. > > > > Well I just tested with -U -u together no joy. Tested with -U no joy. My read of the above is -u should cause a return code of 2 when the file hierarchy does not match the specification. I don't want -U because I am not modifying any content of the directory tree mtree is looking at. I just don't get the point your trying to make. Oh the other hand are you saying the script code is correct to capture the return code but using wrong options with mtree ?