[Ocfs2-tools-devel] [PATCH] A new ocfs2 configure file vertify
tool.
Joel Becker
Joel.Becker at oracle.com
Wed Jan 30 16:44:24 PST 2008
On Wed, Jan 30, 2008 at 05:35:57PM +0800, shawn wrote:
> > 1. Blindly creating /tmp/ocfs2/... is not good. We may overwrite
> > some useful stuff. Use mktemp to create a temp dir under /tmp.
> >
> yes,that is a problem ,but what I need is a directory, mktemp can only
> create a temp file for use,so I used the timestamp as the subdir in this
> directory, and after complete delete this subdir immediately.So I think
> that won't be a problem.
Use "mktemp -d". An example:
-----------------------------------------------------------
WORKFILES=
WORKDIR=
trap "exitcode=\$?; (rm -f \$WORKFILES 2>/dev/null; rmdir \$WORKDIR
2>/dev/null) && exit \$exitcode" 0
trap "rm -f \$WORKFILES 2>/dev/null; rmdir \$WORKDIR 2>/dev/null" 1 2 13 15
WORKDIR="$(mktemp -d "${TMPDIR:-/tmp}/o2cb_verify.XXXXXX" 2>/dev/null)"
if [ -z "$WORKDIR" -o ! -d "$WORKDIR" ]
then
echo "Unable to create temporary directory" >&2
exit 1
fi
ERRLOG="${WORKDIR}/error.log"
WORKFILES="$ERRLOG $WORKFILES"
-----------------------------------------------------------
The trap call will clean up WORKDIR on SIGTERM, SIGHUP, SIGINT, SIGPIPE,
and any regular exit, including normal program termination. So you
don't need a separate cleanup step.
Whenever you are about to create another file in WORKDIR, add it
to WORKFILES first. In your script again, where you connect to hosts:
+WORKFILES="$WORKDIR/$1 $WORKFILES"
ssh -oConnectTimeout=$TIMEOUT "$connect_str" $COMMAND 1> "$WORKDIR/$1" 2>>$ERRLOG
Joel
--
"I don't know anything about music. In my line you don't have
to."
- Elvis Presley
Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
More information about the Ocfs2-tools-devel
mailing list