bug-bash
[Top][All Lists]
Advanced

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

Re: exit status issue


From: Greg Wooledge
Subject: Re: exit status issue
Date: Tue, 22 Nov 2011 12:44:42 -0500
User-agent: Mutt/1.4.2.3i

On Tue, Nov 22, 2011 at 11:31:22AM -0600, Dallas Clement wrote:
> It turns out that my 'touch' command is actually getting executed, but
> not when I expect it.  Here is a recap of my script function which is
> occasionally misbehaving:
> 
> # $1 mntpoint
> fsaccesstest()
> {
>       local RETRY_MAX=3
>       local RETRY_INTERVAL=3
>       local CHK_RESULT=1
> 
>       TMP=`grep $1 /proc/mounts|awk '{print $1}'`
>       if [ "$TMP" != "" ]; then
>               for i in `seq 1 ${RETRY_MAX}`
>               do
>                       touch $1/.accesstest
>                       CHK_RESULT=$?
>                       if [ ${CHK_RESULT} -eq 0 ] ; then
>                               break
>                       fi
>                       logger -s -t ${LOGTAG} -p ${LOGFACILITY} "*** 
> fsaccesstest test $1
> failed. retrying... (${i}) ***"
>                       sleep ${RETRY_INTERVAL}
>               done
>               if [ $CHK_RESULT -ne 0 ]; then
>                       logger -t ${LOGTAG} -p ${LOGFACILITY} "*** fsaccesstest 
> test $1 failed. ***"
>                       echo "*** fsaccess test $1 failed. ***" >/dev/console
>                       ## try remount it
>                       umount $1
>                       mount $TMP $1
>                       return $?
>               fi
>               return 0
>       fi
>       return 1
> }

> In the failure scenario, I had wrongly assumed that the touch command
> was not being executed, when in fact it is.  It's just that the
> execution is deferred somehow and occurs after the call to 'logger',
> which would not have been executed had the call to 'touch' somehow
> failed or returned too soon.

That makes no sense.  Fix your quoting (it's atrocious) and then run
the function with "set -x".  Don't throw strace at it, at this point.
It's really not the right tool at this level of debugging.

Also note that there are *two* calls to logger in this function.  You
might be mistaking which logger call you are seeing, particularly since
you're trying to debug with the wrong tool.

If I understand what this function is attempting to do:

fstest() {
    local i=0
    while ((++i < 3)); do
        # If it's mounted, yay!
        df "$1" && return 0

        # It's not mounted, so try to trigger autofs.
        touch "$1"/.accesstest
        sleep 3
    done

    # We failed 3 times, so give up.
    return 1
}

I don't even know what your actual *symptom* is.  I can't deduce it from
a spew of strace output.  You haven't described the reason for the touch
command, so I can only presume this is some sort of autofs environment,
hence my attempt to solve the issue, above.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]