Script giving error-Unable to identfiy


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script giving error-Unable to identfiy
# 1  
Old 12-17-2013
Script giving error-Unable to identfiy

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(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

Code:
Host OK
targ OK
host = dev-oragrid-ux01 targ = pref
test4.sh[28]: syntax error at line 36 : `(' unexpected


Please assist


Best regards,
Vishal
# 2  
Old 12-17-2013
Try changing your for loop to this:

Code:
for ((i=0;i<${#lines[@]};i++))

# 3  
Old 12-17-2013
A numeric for loop uses double brackets
Code:
for ((i=0;i<${#lines[@]};i++))

# 4  
Old 12-17-2013
It's still giving the same error:

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';


Below is the error:

Code:
Host OK
targ OK
host = dev-oragrid-ux01 targ = pref
test4.sh[28]: syntax error at line 36 : `(' unexpected


Best regards,
Vishal
# 5  
Old 12-17-2013
Hello Vishal,

Not sure if you have posted the complete script, buyt seems the for loop should be closed by done.

try the same and let us know.


Thanks,
R. Singh
# 6  
Old 12-17-2013
Below is the complete script


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;};;
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


Best regards,
Vishal
# 7  
Old 12-17-2013
BTW: the array lines will always hold one element, you have to use the array initializer instead:
Code:
$ declare -a lines
$ lines=`cat /etc/profile`
$ echo ${#lines[@]}
1
$ lines=( `cat /etc/profile` )
$ echo ${#lines[@]}
266

This will also not solve the syntax error at line 36 : `(' unexpected error. Please post the entire script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

HP-UX: Shell Script giving " 0^J30: Syntax error"

Hi All, We are getting a very unique error while running a shell script on HP-UX box. Can somebody help in this regards? The shell script is working fine on linux/solaris box. Error: ++++++++++++++++++++++++ $/test.sh ./test.sh: 0^J30: Syntax error $ ++++++++++++++++++++++++ TIA.... (16 Replies)
Discussion started by: vai_sh
16 Replies

2. Shell Programming and Scripting

Unable to identify error in the script

cat test3.sh #!/bin/sh set -x while getopts ":n:" opt; do case "$opt" in n) host=$OPTARG shift 2 ;; -h ) host=$2 shift 2 ;; *) break ;; esac done; echo "host =... (7 Replies)
Discussion started by: Vishal_dba
7 Replies

3. Shell Programming and Scripting

script to kill a pid giving error

Hi, I simply want to kill a running process using a script that read pid from a file and tries to kill it .Getting error as shown below code.. cat $HOME/BackupScript.ksh.run | head -1 | while read pid do ps -p $pid > /dev/null 2>&1 if ; then kill -9 $pid else echo "no running $pid... (5 Replies)
Discussion started by: dhirajdsharma
5 Replies

4. AIX

multipath giving error

Hi, # lspath Missing hdisk0 fscsi0 Missing hdisk1 fscsi0 Missing hdisk2 fscsi0 Missing hdisk3 fscsi0 Missing hdisk4 fscsi0 Missing hdisk5 fscsi0 Missing hdisk6 fscsi0 Missing hdisk7 fscsi0 Missing hdisk8 fscsi0 Missing hdisk9 fscsi0 Missing hdisk10 fscsi0 Missing hdisk11... (2 Replies)
Discussion started by: JATA01
2 Replies

5. Shell Programming and Scripting

Script working in AIX, but giving error in SOLARIS

Hi, My script is working fine in AIX but throwing an error in SOLARIS system. Here is the error message that I am getting when calculating the elapsed time: /home/x772525/FindETA.sh: start_mins = *60 + : syntax error . ((start_mins = $(expr substr "$j" 1 2)*60 + $(expr substr "$j" 4... (6 Replies)
Discussion started by: ajayakunuri
6 Replies

6. Shell Programming and Scripting

bc giving error: (standard_in) 2: parse error

Below part of script, is working fine sometimes and gives error sometime. I am doing float operations, checking if x > y. ##########CODE########## THRESHOLD="1.25" ratio=$( echo "scale=2; ${prev}/${current}" | bc ) if ; then split_date=`echo ${line} | cut -d, -f2` fi ... (9 Replies)
Discussion started by: manishma71
9 Replies

7. Shell Programming and Scripting

Printer status script giving error

Hi, We check the printer status at the command line by giving the following command and the system gives an output; lpstat -prn001_hp4000n When I give the same command in a UNIX script the system gives an error while running the script as "lpstat: not found". Please let me know... (8 Replies)
Discussion started by: jmathew99
8 Replies

8. Shell Programming and Scripting

A running Script giving error while scheduled in cronjob

Hi, I have script which is properly running but when i schedule it in cron it throws an error like : Your "cron" job on retrprdapp1 /usr/bin/sh /retr/cron/ftp.sh 2>&1 produced the following output: /retr/cron/ftp.sh: syntax error at line 17: `(' unexpected line17 is # Get list of... (10 Replies)
Discussion started by: rajagasti
10 Replies

9. UNIX for Advanced & Expert Users

script giving error

Hi All, i have an small issue... echo " " eval x=$@ export x=`echo $x` echo $x ssh user@ipadrss; cd /mbbv/home/; cd /mbbv/home/orange/orange/ echo pwd bash samplescript.sh $x above is my script which will triger from server A and will connect to server B for some... (2 Replies)
Discussion started by: Shahul
2 Replies

10. Shell Programming and Scripting

mv command is giving error in shell script

Hi, In my shell script when I am using mv command using shell variables it is giving me error of syntax. Following is the shell script: file_edifice="*.txt" fquote="'" fdquote=\" for file in $file_edifice do file_name=$fquote$file$fquote tofile_name=`date... (5 Replies)
Discussion started by: gammit
5 Replies
Login or Register to Ask a Question