2007-11-27 12:53:18 +00:00
|
|
|
#!/bin/sh
|
2010-04-06 17:12:18 +00:00
|
|
|
#test
|
2007-10-26 22:44:33 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
2008-03-05 16:49:19 +00:00
|
|
|
|
|
|
|
# Opens the specified table in the users editor and writes changes back to the db
|
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
function cexit {
|
|
|
|
if [ -d /tmp/tabedit.$$ ]; then
|
|
|
|
rm -rf /tmp/tabedit.$$;
|
|
|
|
fi
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
trap cexit 2 15
|
|
|
|
|
2010-04-15 08:06:26 +00:00
|
|
|
if [ `uname` == Linux ]; then
|
|
|
|
#Source for environment variables
|
|
|
|
source /etc/profile.d/xcat.sh
|
|
|
|
fi
|
2010-04-06 17:12:18 +00:00
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
TABLE=$1
|
2008-01-26 17:55:34 +00:00
|
|
|
if [ -z "$TABEDITOR" ]; then
|
|
|
|
TABEDITOR=$EDITOR
|
|
|
|
fi
|
|
|
|
if [ -z "$TABEDITOR" ]; then
|
|
|
|
#echo "WARNING: Define TABEDITOR or EDITOR environment variable before running this command"
|
|
|
|
TABEDITOR=vi
|
2007-10-26 22:44:33 +00:00
|
|
|
fi
|
2008-03-05 16:49:19 +00:00
|
|
|
if [ -z "$TABLE" -o "$TABLE" = "-?" -o "$TABLE" = "-h" -o "$TABLE" = "--help" ]; then
|
2007-10-26 22:44:33 +00:00
|
|
|
echo "Usage: tabedit <tablename>";
|
2008-03-05 16:49:19 +00:00
|
|
|
echo " tabedit [-? | -h | --help]";
|
2007-10-26 22:44:33 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2008-03-05 16:49:19 +00:00
|
|
|
|
|
|
|
# Dump the table to a temporary file
|
2007-10-26 22:44:33 +00:00
|
|
|
mkdir -p /tmp/tabedit.$$/
|
2010-04-06 17:12:18 +00:00
|
|
|
$XCATROOT/bin/xcatclientnnr tabdump $TABLE > /tmp/tabedit.$$/$TABLE.csv
|
2008-03-05 16:49:19 +00:00
|
|
|
|
|
|
|
# Save the checksum to see if it actually changes..
|
|
|
|
if [ `uname` = "AIX" ]; then
|
|
|
|
SUMPROGRAM=sum
|
|
|
|
else
|
|
|
|
SUMPROGRAM=md5sum
|
|
|
|
fi
|
|
|
|
SUM=`$SUMPROGRAM /tmp/tabedit.$$/$TABLE.csv`
|
|
|
|
|
|
|
|
# Edit the file, then check it
|
2007-10-26 22:44:33 +00:00
|
|
|
EXIT=0
|
|
|
|
while [ $EXIT -eq 0 ]; do
|
|
|
|
cd /tmp/tabedit.$$
|
2010-02-23 11:14:40 +00:00
|
|
|
$TABEDITOR $TABLE.csv
|
2008-03-05 16:49:19 +00:00
|
|
|
cd - >/dev/null
|
|
|
|
NEWSUM=`$SUMPROGRAM /tmp/tabedit.$$/$TABLE.csv`
|
2007-10-26 22:44:33 +00:00
|
|
|
if [ "$NEWSUM" == "$SUM" ]; then
|
|
|
|
echo "No file modifications detected, not restoring."
|
|
|
|
break;
|
|
|
|
fi
|
2008-03-05 16:49:19 +00:00
|
|
|
if `dirname $0`/tabrestore /tmp/tabedit.$$/$TABLE.csv; then
|
2007-10-26 22:44:33 +00:00
|
|
|
break;
|
|
|
|
else
|
|
|
|
echo "Above errors occured, hit enter to edit, or ctrl-c to abort"
|
|
|
|
read JNK
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
cexit
|
|
|
|
|