Skip to content

Instantly share code, notes, and snippets.

@jkstill
Last active December 10, 2015 02:58
Show Gist options
  • Save jkstill/4371142 to your computer and use it in GitHub Desktop.
Save jkstill/4371142 to your computer and use it in GitHub Desktop.
:
function usage {
echo $0
echo
echo -m info:oratab
echo
echo Get a report on missing oratab entries
echo $0 -m info
echo
echo Output used to rewrite oratab
echo $0 -m oratab
echo
}
# needs an option to specify oratab location
# with a default of /etc/oratab
ORATAB=/etc/oratab
while getopts m: arg
do
case $arg in
m) MODE=$OPTARG;;
*) usage;exit 1;;
esac
done
case $MODE in
info|oratab);;
*) usage;exit 2;;
esac
########################
if [ "$MODE" == 'info' ]; then
########################
ps -e -o pid,cmd | grep [p]mon | sed -e 's/^ //g' | while read opid oproc
do
echo '##########################################################################'
osid=$(echo $oproc | cut -d_ -f3)
ohome=$(lsof -p $opid | grep bin.oracle | awk -F/ '{ohome=""; for(i=2;i<=NF-2;i++){printf "/%s", $i}} END{printf "\n"}')
echo PID: $opid PROC: $oproc SID: $osid OHOME: $ohome
FOUNDINORATAB=$(grep $osid:$ohome $ORATAB)
if [ -z "$FOUNDINORATAB" ] ; then
echo "!! not found in ORATAB !!"
echo ORATAB ENTRY: $osid:$ohome:N
else
echo ORATAB ENTRY: $FOUNDINORATAB
fi
done
########################
elif [ "$MODE" == 'oratab' ]; then
########################
# make sure that all instances in oratab are up
# any that are not up need to be included in the output
# still needs to account for duplicates that may be down
TMPORATAB=/tmp/oratab.$$
> $TMPORATAB
for instance in $(grep "^[A-Z|a-z]" $ORATAB | cut -f1 -d:)
do
cmd="ps -flea | grep [o]ra_pmon_$instance"
#echo cmd: $cmd
output=$(eval $cmd)
#echo $output
[ -z "$output" ] && {
#echo instance $instance is not up!
grep "^$instance" $ORATAB >> $TMPORATAB
}
done
ps -e -o pid,cmd | grep [p]mon | sed -e 's/^ //g' | while read opid oproc
do
osid=$(echo $oproc | cut -d_ -f3)
ohome=$(lsof -p $opid | grep bin.oracle | awk -F/ '{ohome=""; for(i=2;i<=NF-2;i++){printf "/%s", $i}} END{printf "\n"}')
echo $osid:$ohome:N
done >> $TMPORATAB
DUPLICATES=$(cut -f1 -d: $TMPORATAB | sort | uniq -d)
[ -n "$DUPLICATES" ] && {
echo
echo !! Warning !!
echo The following SIDs are duplicated
echo You will need to comment all but one of the duplicates
echo
echo $DUPLICATES
echo
}
sort $TMPORATAB
rm -f $TMPORATAB
#echo $TMPORATAB
########################
else
########################
echo Some error has occurred - the script should never reach this code
exit 3
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment