The following script shows how to check an Oracle SID to be sure that it’s valid. The script expects the SID to be passed in as the first parameter, and it begins by checking to see if a parameter was even passed. The script next counts the number of times the first parameter value appears in the /etc/oratab file. A valid Oracle SID will appear once in that file.
#!/bin/ksh
# Exit if no first parameter $1 passed.
if [ -z “$1” ]
then
echo “Please pass a valid ORACLE_SID
to this script”
exit 99
fi
# Validate the Oracle database name with
# lookup in /etc/oratab.
TEMP=`cat /etc/oratab|grep ^$1:|
cut -f1 -d’:’|wc -l`
tmp=`expr TEMP` # Convert string to number.
if [ $tmp -ne 1 ]
then
echo “Your input $1 is not a valid ORACLE_SID.”
exit 99
fi