Bite me! <jay(_at_)drooley(_dot_)accessus(_dot_)net> writes:
Can anybody clarify for me how to gather the return status for the
lockfile command?
I've checked out the lockfile(1) man and it didn't really seem to specify
and is pretty darn brief to be honest. ;)
This is just basic shell programming technique; that's why it's not
documented on the lockfile manpage. If you want to test the return
code right after running lockfile, you can just make it the conditional
of an if statement:
if lockfile -ml; then
# lockfile succeeded. Move the mailbox, or whatever
cp $MAIL $HOME/in
cp /dev/null $MAIL
lockfile -mu
else
# lockfile failed, scream. The ">&2" sends the message
# to stderr instead of stdout
echo "Unable to lock $MAIL" >&2
exit 42
fi
Otherwise, if you want to save the exitcode for later testing, you'll
find it in $? right after running the command:
lockfile $HOME/foo.lock
exitcode=$?
# do stuff, unsure of whether the lock succeeded or not
if test $exitcode -eq 0; then
# zero is success...
process_mailbox $HOME/foo
rm -f $HOME/foo.lock
else
# non-zero is failure
echo "help me, help me!" >&2
fi
Philip Guenther