1
0
Files
2022-09-29 17:59:04 +03:00

313 lines
6.5 KiB
Bash
Executable File

#!/bin/sh
Usage()
{
echo "Usage: $1 -s [hostname] [classcode] [typecode]"
echo " $1 -u [hostname] [-d]"
echo " "
echo " where, "
echo " -s subscribe"
echo " -u unsubscribe"
echo " -d delete entries from data tables also"
exit 1
}
UnSubscribe()
{
SYSID=`echo "select sys_id from system where hostname like '$1%';" | mysql ssdb | tail -1`
if [ "$SYSID" = "" ] ; then
echo "$TAB1 Can't find System Information for $1"
exit 1
fi
echo "$TAB1 Generating SQL Statement for SYSTEM Table "
echo "delete from system where sys_id = '$SYSID';" >> $TMPFILENAME
echo "$TAB1 Generating SQL Statement for event_type Table "
echo "delete from event_type where sys_id = '$SYSID';" >> $TMPFILENAME
if [ "$2" = "" ] ; then
YN=""
while true
do
if [ "$YN" = "" ] ; then
echo -n "$TAB1 Do you want to delete data from data tables ? "
read YN
else
break
fi
done
if [ "$YN" = "Y" -o "$YN" = "y" ] ; then
DELETEENTRIES=Y
else
DELETEENTRIES=N
fi
else
if [ "$2" = "-d" ] ; then
DELETEENTRIES=Y
else
DELETEENTRIES=N
fi
fi
if [ "$DELETEENTRIES" = "Y" ] ; then
echo "$TAB1 Generating SQL Statement for system_data table"
echo "delete from system_data where sys_id = '$SYSID';" >> $TMPFILENAME
echo "$TAB1 Generating SQL Statement for event table"
echo "delete from event where sys_id = '$SYSID';" >> $TMPFILENAME
fi
AutoUpdate
}
AutoUpdate()
{
YN=""
while true
do
if [ "$YN" = "" ] ; then
echo -n "$TAB1 Do you want to update SSDB automatically ? "
read YN
else
break;
fi
done
if [ "$YN" = "Y" -o "$YN" = "y" ] ; then
mysql ssdb < $TMPFILENAME
rm -f $TMPFILENAME
else
echo "$TAB1 Please use the following for manual updates "
echo "$TAB3 mysql ssdb < $TMPFILENAME"
echo "$TAB3 rm -f $TMPFILENAME"
fi
}
TMPFILENAME=/usr/tmp/sgmsql.$$
TAB1="\t-->"
TAB2="\t o"
TAB3="\t o "
if [ k$1 = "k" ] ; then
Usage $0
fi
if [ k$1 = "k-h" ] ; then
Usage $0
fi
if [ $1 = "-s" ] ; then
echo "--------------------------------------------------------------"
echo " System Group Manager - Subscription"
echo "--------------------------------------------------------------"
else
echo "--------------------------------------------------------------"
echo " System Group Manager - UnSubscription"
echo "--------------------------------------------------------------"
fi
if [ k$2 = "k" ] ; then
HOSTNAME=""
else
HOSTNAME=$2
fi
if [ k$3 = "k" ] ; then
CLASS=""
else
CLASS=$3
fi
if [ k$4 = "k" ] ; then
TYPEFROM=""
else
TYPEFROM=$4
fi
while true
do
if [ "$HOSTNAME" = "" ] ; then
echo -n "$TAB1 Enter Hostname : "
read HOSTNAME
else
break;
fi
done
echo "$TAB1 Gathering variables for $HOSTNAME"
if [ $1 = "-u" ] ; then
UnSubscribe $HOSTNAME $CLASS
exit 0
fi
NOHOSTS=`cat /etc/hosts | grep -v ^# | grep -v '^ '| grep $HOSTNAME | wc -l| awk '{print $1}'`
if [ $NOHOSTS -eq 0 ] ; then
echo "$TAB1 No hosts match your query in /etc/hosts."
exit 1
fi
if [ $NOHOSTS -gt 1 ] ; then
echo "$TAB1 More than one host ($NOHOSTS) match your query. Please be specific"
exit 1
fi
HOSTIPADDR=`cat /etc/hosts | grep -v ^# | grep -v '^ '| grep $HOSTNAME|awk '{print $1}'`
HOSTNAMEFULL=`cat /etc/hosts | grep -v ^# | grep -v '^ '| grep $HOSTNAME|awk '{print $2}'`
#
# Get System Information
#
SYSINFOVV=`rsh guest@$HOSTNAMEFULL sysinfo -vv 2>/dev/null`
if [ "$SYSINFOVV" = "" ] ; then
echo -n "$TAB1 Can't log-in to the guest account of $HOSTNAMEFULL\n"
TMPSYSID=""
while true
do
if [ "$TMPSYSID" = "" ] ; then
echo -n "$TAB2 Enter System ID (decimal) : "
read TMPSYSID
else
break;
fi
done
SERIALNUM=""
while true
do
if [ "$SERIALNUM" = "" ] ; then
echo -n "$TAB2 Enter System Serial Number : "
read SERIALNUM
else
break;
fi
done
IPTYPE=""
while true
do
if [ "$IPTYPE" = "" ] ; then
echo -n "$TAB2 Enter IP Type : "
read IPTYPE
else
break;
fi
done
else
TMPSYSID=`echo $SYSINFOVV | awk '{print $1}'`
SERIALNUM=`echo $SYSINFOVV | awk '{print $2}'`
IPTYPE=`rsh guest@$HOSTNAMEFULL uname -m | cut -c 3-`
fi
SYSID=`printf "%X" $TMPSYSID`
MAXRECKEY=`echo "select max(rec_key) from system" | mysql ssdb 2>/dev/null | tail -1`
MAXRECKEY=${MAXRECKEY:=1000}
NEXTRECKEY=`expr $MAXRECKEY + 1`
#
# Confirmation of host details
#
echo -n "\n"
echo "$TAB1 The following variables will be entered in System Table: \n"
echo "$TAB2 Next Rec Key : $NEXTRECKEY"
echo "$TAB2 System ID : $SYSID"
echo "$TAB2 Serial Number : $SERIALNUM"
echo "$TAB2 Host Name : $HOSTNAMEFULL"
echo "$TAB2 IP Address : $HOSTIPADDR"
echo "$TAB2 IP Type : $IPTYPE"
echo -n "\n"
YN=""
while true
do
if [ "$YN" = "" ] ; then
echo -n "$TAB2 Are there variables OK (Y/N) ? "
read YN
else
if [ "$YN" = "Y" -o "$YN" = "y" ] ; then
break
else
exit 1
fi
fi
done
echo -n "\n"
echo "$TAB1 Generating SQL Statement for SYSTEM Table "
echo "insert into system values ($NEXTRECKEY,'$SYSID',$IPTYPE,'$SERIALNUM','$HOSTNAMEFULL','$HOSTIPADDR',1,0,`/var/adm/avail/amtime1970`);" > $TMPFILENAME
echo "$TAB1 Time to enter Classes & Types of Events to subscribe"
YN="Y"
while true
do
if [ "$YN" = "Y" -o "$YN" = "y" ] ; then
while true
do
if [ "$CLASS" = "" ] ; then
echo -n "$TAB3 Enter Class Code : "
read CLASS
else
break
fi
done
while true
do
if [ "$TYPEFROM" = "" ] ; then
echo -n "$TAB3 Enter Starting Type Code for $CLASS : "
read TYPEFROM
else
break
fi
done
TYPETO=$TYPEFROM
echo -n "$TAB3 Enter Ending Type Range for $CLASS : "
read TYPETO
if [ "$TYPETO" = "" ] ; then
TYPETO=$TYPEFROM
fi
if [ $TYPETO -lt $TYPEFROM ] ; then
TMPTYPE=$TYPEFROM
TYPEFROM=$TYPETO
TYPETO=$TMPTYPE
fi
echo -n "\n"
echo "$TAB1 Generating SQL Statements for EVENT_TYPE Table"
while true
do
if [ $TYPEFROM -le $TYPETO ] ; then
echo -n "insert into event_type values('$SYSID', " >> $TMPFILENAME
echo "$TYPEFROM, $CLASS, ' ', 0, 0, 0, -1, 1);" >> $TMPFILENAME
TYPEFROM=`expr $TYPEFROM + 1`
else
break
fi
done
YN=""
while true
do
if [ "$YN" = "" ] ; then
echo -n "$TAB1 Do you want to enter more classes ? "
read YN
else
CLASS=""
TYPEFROM=""
TYPETO=""
break
fi
done
else
break;
fi
done
AutoUpdate
exit 0