#!/bin/sh
#!/bin/prel
#set -x
while getopts ":n:t:" opt; do
case "$opt" in
n)
host=$OPTARG
;;
t)
targ=$OPTARG
;;
*)
break
;;
esac
done
if ping -c 2 $host >/dev/null 2>&1
then
echo Host OK
else
echo Bad Host $host
fi
case "$targ" in
pref|avail) echo targ OK;;
*) echo Bad argument to -t;;
esac
echo "host = $host targ = $targ"
calc_pref_avail(y to check the dba_jobs job last execution time till completion (time taken by job in last run))
{
declare -a lines
declare -a pref
declare -a avail
IFS=$'\n';
lines=`srvctl config service -d ${1} -s ${2}|egrep '^(Preferred|Available) instances:'`;
for (i=0;i<${#lines[@]};i++)
do
line=${lines[$i]};
IFS=$'\n';
if [ "${line:0:21}" = 'Preferred instances: ' ]; then
Below is the error
Host OK
targ OK
host = dev-oragrid-ux01 targ = pref
test4.sh[28]: syntax error at line 36 : `(' unexpected
#!/bin/sh
#!/bin/prel
#set -x
while getopts ":n:t:" opt; do
case "$opt" in
n)
host=$OPTARG
;;
t)
targ=$OPTARG
;;
*)
break
;;
esac
done
if ping -c 2 $host >/dev/null 2>&1
then
echo Host OK
else
echo Bad Host $host
fi
case "$targ" in
pref|avail) echo targ OK;;
*) echo Bad argument to -t;;
esac
echo "host = $host targ = $targ"
calc_pref_avail()
{
declare -a lines
declare -a pref
declare -a avail
IFS=$'\n';
lines=`srvctl config service -d ${1} -s ${2}|egrep '^(Preferred|Available) instances:'`;
for ((i=0;i<${#lines[@]};i++))
do
line=${lines[$i]};
IFS=$'\n';
Below is the error:
Host OK
targ OK
host = dev-oragrid-ux01 targ = pref
test4.sh[28]: syntax error at line 36 : `(' unexpected
#!/bin/sh
#!/bin/prel
#set -x
while getopts ":n:t:" opt; do
case "$opt" in
n)
host=$OPTARG
;;
t)
targ=$OPTARG
;;
*)
break
;;
esac
done
if ping -c 2 $host >/dev/null 2>&1
then
echo Host OK
else
echo Bad Host $host
fi
case "$targ" in
pref|avail) echo targ OK;;
*) echo Bad argument to -t;;
esac
echo "host = $host targ = $targ"
calc_pref_avail()
{
declare -a lines
declare -a pref
declare -a avail
IFS=$'\n';
lines=`srvctl config service -d ${1} -s ${2}|egrep '^(Preferred|Available) instances:'`;
for ((i=0;i<${#lines[@]};i++))
do
line=${lines[$i]};
IFS=$'\n';
if [ "${line:0:21}" = 'Preferred instances: ' ]; then
pref=($(echo "${line:21}"|sed 's/,/\n/g'));
else
avail=($(echo "${line:21}"|sed 's/,/\n/g'));
fi
done
# array with preferred instances
for ((m=0;m<${#pref[@]};m++))
do
echo " ${pref[$m]} "
done
# array with available instances
for ((m=0;m<${#avail[@]};m++))
do
echo " ${avail[$m]} "
done
}
export CRS_HOME=/devoragridcn_01/Grid_11203
for database in `$CRS_HOME/bin/crsctl status res -n $host| grep -E "ora.*\.db" | awk -F"." '{print $(NF-1)}'`
do
export ORACLE_HOME=`$CRS_HOME/bin/srvctl config database -v|grep -i $database | awk '{print $2}'`
for service in `$ORACLE_HOME/bin/srvctl status service -d $database | awk '{print $2}'`
do
c="/product/10"
case $ORACLE_HOME in
*/product/10*)
Instance_pref=`$ORACLE_HOME/bin/srvctl config service -s $service -d $database | sed 's/\(.*: \)\(.*\)\( AVAIL:.*\)/\2/1;1q'`
Instance_avail=`$ORACLE_HOME/bin/srvctl config service -s $service -d $database | sed 's/\(.*AVAIL: \)\(.*\)/\2/g;1q'`;;
*)
calc_pref_avail $database $service| { read Pref Avail;};;
echo $Pref "For 11g"
echo $Instance_pref "For 10g";
echo $Instance_avail "For 10g"
echo $Avail "For 10g"
$pref_node=`$ORACLE_HOME/bin/srvctl status database -d $database | sed 's/\(.*Instance\)\(.*\)\( is running on node $node.*\)/\2/1;1q'`
#if $pref_node == $Instance_pref then
#$ORACLE_HOME/bin/srvctl relocate service -s $service -d $database -i #$Instance_pref -t $Instance_avail
done
done
I have done the corrections -it's still giving error .Please see the update code
#!/bin/sh
#!/bin/prel
#set -x
while getopts ":n:t:" opt; do
case "$opt" in
n)
host=$OPTARG
;;
t)
targ=$OPTARG
;;
*)
break
;;
esac
done
if ping -c 2 $host >/dev/null 2>&1
then
echo Host OK
else
echo Bad Host $host
fi
case "$targ" in
pref|avail) echo targ OK;;
*) echo Bad argument to -t;;
esac
echo "host = $host targ = $targ"
calc_pref_avail()
{
declare -a lines
declare -a pref
declare -a avail
IFS=$'\n';
lines=`srvctl config service -d ${1} -s ${2}|egrep '^(Preferred|Available) instances:'`;
for ((i=0;i<${#lines[@]};i++))
do
line=${lines[$i]};
IFS=$'\n';
if [ "${line:0:21}" = 'Preferred instances: ' ]; then
pref=($(echo "${line:21}"|sed 's/,/\n/g'));
else
avail=($(echo "${line:21}"|sed 's/,/\n/g'));
fi
done
# array with preferred instances
for ((m=0;m<${#pref[@]};m++))
do
echo " ${pref[$m]} "
done
# array with available instances
for ((m=0;m<${#avail[@]};m++))
do
echo " ${avail[$m]} "
done
}
export CRS_HOME=/devoragridcn_01/Grid_11203
for database in `$CRS_HOME/bin/crsctl status res -n $host| grep -E "ora.*\.db" | awk -F"." '{print $(NF-1)}'`
do
export ORACLE_HOME=`$CRS_HOME/bin/srvctl config database -v|grep -i $database | awk '{print $2}'`
for service in `$ORACLE_HOME/bin/srvctl status service -d $database | awk '{print $2}'`
do
c="/product/10"
case $ORACLE_HOME in
*/product/10*)
Instance_pref=`$ORACLE_HOME/bin/srvctl config service -s $service -d $database | sed 's/\(.*: \)\(.*\)\( AVAIL:.*\)/\2/1;1q'`
Instance_avail=`$ORACLE_HOME/bin/srvctl config service -s $service -d $database | sed 's/\(.*AVAIL: \)\(.*\)/\2/g;1q'`;;
*)
calc_pref_avail $database $service| { read Pref Avail;};;
esac
echo $Pref "For 11g"
echo $Instance_pref "For 10g";
echo $Instance_avail "For 10g"
echo $Avail "For 10g"
pref_node=`$ORACLE_HOME/bin/srvctl status database -d $database | sed 's/\(.*Instance\)\(.*\)\( is running on node $node.*\)/\2/1;1q'`
#if $pref_node == $Instance_pref then
#$ORACLE_HOME/bin/srvctl relocate service -s $service -d $database -i $Instance_pref -t $Instance_avail
done
done
sh test4.sh -n dev-oragrid-ux01 -t pref
Host OK
targ OK
host = dev-oragrid-ux01 targ = pref
test4.sh[28]: syntax error at line 36 : `(' unexpected
When you use ./test4.sh , then the script is "executed" by the kernel. Now the script is just text and not a executable binary. So the kernel needs to execute an "interpreter" instead. If the file starts with #! , then the kernel recognizes this and executes the program defined between #! and the first newline character. The name of the script is passed as commandline argument to the interpreter.
When you type sh test4.sh , then you directly call the program sh and pass the scriptname on the commandline. The first line of the script is just a comment in this case and has no special meaning.