2007-11-27 12:53:18 +00:00
|
|
|
#!/bin/sh
|
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
|
|
|
|
2010-04-30 12:00:33 +00:00
|
|
|
# Opens the specified table in the users editor;writes changes back to the db
|
2008-03-05 16:49:19 +00:00
|
|
|
|
2011-08-17 18:49:15 +00:00
|
|
|
cexit () {
|
2007-10-26 22:44:33 +00:00
|
|
|
if [ -d /tmp/tabedit.$$ ]; then
|
|
|
|
rm -rf /tmp/tabedit.$$;
|
|
|
|
fi
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
trap cexit 2 15
|
|
|
|
|
2010-04-15 14:44:48 +00:00
|
|
|
if [ -r /etc/profile.d/xcat.sh ]; then
|
2010-04-15 08:06:26 +00:00
|
|
|
#Source for environment variables
|
2011-08-17 18:49:15 +00:00
|
|
|
. /etc/profile.d/xcat.sh
|
2010-04-15 08:06:26 +00:00
|
|
|
fi
|
2010-04-06 17:12:18 +00:00
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
TABLE=$1
|
2010-04-30 12:00:33 +00:00
|
|
|
|
2011-03-08 13:14:44 +00:00
|
|
|
if [ "$TABLE" = "eventlog" ] || [ "$TABLE" = "auditlog" ]; then
|
2011-01-28 16:31:16 +00:00
|
|
|
echo "The auditlog and eventlog tables may not be edited. Editing will cause index regeneration. Use the tabprune command.";
|
2010-04-30 12:00:33 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
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`
|
2011-08-17 18:49:15 +00:00
|
|
|
if [ "$NEWSUM" = "$SUM" ]; then
|
2007-10-26 22:44:33 +00:00
|
|
|
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
|
|
|
|
|