ERROR: `(' is not expected.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ERROR: `(' is not expected.
# 1  
Old 01-31-2013
ERROR: `(' is not expected.

Hi All,

I have written a shell script which works all right on bash shell, but when it comes to execute it using ksh on AIX it gives the following error:Smilie

Code:
    bash$ /bin/ksh getShortInfo.sh 
    getShortInfo.sh[10]: syntax error at line 26 : `(' unexpected

Could you please indicate what is wrong? In addition, if you could indicate how can I make it portable on bash/ksh/csh would be really appreciated.

Please you can find below the guilty part of the script:

Code:
#!/bin/sh

COMMANDS=""
file_name='systemInfo.txt'
OS_TYPE=`uname`


getCommandsSpecificOS(){
    AIX_COMMANDS[0]="hostname"

    SunOS_COMMANDS[1]="uname -a"
    SunOS_COMMANDS[2]="ulimit -a"

    Linux_COMMANDS[0]="hostname"
    Linux_COMMANDS[3]="cat /proc/cpuinfo"
    Linux_COMMANDS[4]="cat /proc/meminfo"

    if   [ $1 = "AIX" ]; then 
        COMMANDS=("${AIX_COMMANDS[@]}")
    elif [ $1 = "SunOS" ]; then 
        COMMANDS=("${SunOS_COMMANDS[@]}")
    elif [ $1 = "Linux" ]; then 
        COMMANDS=("${Linux_COMMANDS[@]}")

    fi
}

###################################################################################################

getCommandsSpecificOS $OS_TYPE




Thanks in advance indeed,
Regards,
Elvis


Last edited by Scrutinizer; 02-05-2013 at 10:07 AM.. Reason: code tags
# 2  
Old 01-31-2013
Remove the parens around:
Code:
COMMANDS=("${AIX_COMMANDS[@]}")

This User Gave Thanks to gary_w For This Post:
# 3  
Old 01-31-2013
Quote:
Originally Posted by Elvis
Hi All,

I have written a shell script which works all right on bash shell, but when it comes to execute it using ksh on AIX it gives the following error:Smilie
BASH has arrays.

Most other shells don't.

If you want this to work in shells other than your favorite, you'll want to rewrite it without arrays.

We can help with that, if you could illustrate what you're trying to do.
This User Gave Thanks to Corona688 For This Post:
# 4  
Old 02-05-2013
Hi All,

thank you very much in advance for your support.Smilie

Basically i am trying to get platform' specific information through the use of the script.

The platform could be: SunOS, AIX or RHEL.

The script does not take any argument in input. It visualise on the screen the success or not of the platform' specific commands which are executed for gathering platform specific information.

The script create, in the directortory where it is launched, the file "systemInfo.txt" which contains all platform' specific information.

The script gives also the opportunity to execute further commands
based on the wishes of the user.

Thanks again for your help.

Please, below you can find the script .

Elvis


Code:
#!/bin/sh
  
COMMANDS=""
OS_TYPE='unknown'
file_name='systemInfo.txt'
OS_TYPE=`uname`


getCommandsSpecificOS(){
    AIX_COMMANDS[0]="hostname"
    AIX_COMMANDS[1]="uname -a"
    AIX_COMMANDS[2]="ulimit -a"
    AIX_COMMANDS[3]="smtctl"
    AIX_COMMANDS[4]="swap -l"
    AIX_COMMANDS[5]="/etc/prtconf"
    AIX_COMMANDS[6]="oslevel -s"
    AIX_COMMANDS[7]="lparstat -i"
    AIX_COMMANDS[8]="lscfg -vp | grep -ip proc | grep "PROC""
    AIX_COMMANDS[9]="mpstat"

    SunOS_COMMANDS[0]="hostname"
    SunOS_COMMANDS[1]="uname -a"
    SunOS_COMMANDS[2]="ulimit -a"
    SunOS_COMMANDS[3]='/usr/platform/`uname -i`/sbin/prtdiag'
    SunOS_COMMANDS[4]="/usr/sbin/psrinfo -pv"
    SunOS_COMMANDS[5]="/etc/prtconf"
    SunOS_COMMANDS[6]="cat /etc/release"
    SunOS_COMMANDS[7]="swap -l"
    SunOS_COMMANDS[8]="zoneadm list -vi"



    Linux_COMMANDS[0]="hostname"
    Linux_COMMANDS[1]="uname -a"
    Linux_COMMANDS[2]="ulimit -a"
    Linux_COMMANDS[3]="cat /proc/cpuinfo"
    Linux_COMMANDS[4]="cat /proc/meminfo"
    Linux_COMMANDS[5]="cat /etc/redhat-release"
    Linux_COMMANDS[6]="cat /proc/version"
    Linux_COMMANDS[7]="nvidia-smi  -q"

    if   [ $1 = "AIX" ]; then 
        COMMANDS=("${AIX_COMMANDS[@]}")
    elif [ $1 = "SunOS" ]; then 
        COMMANDS=("${SunOS_COMMANDS[@]}")
    elif [ $1 = "Linux" ]; then 
        COMMANDS=("${Linux_COMMANDS[@]}")
    fi
}

checkStorageFile(){
    if [ -s $1 ]; then
        rm $1
    fi
}

exitStatusDescription(){
    if   [ $1 -eq 127 ]; then 
    echo "$2: Command not found" >> $file_name
    elif [ $1 -eq 126 ]; then 
            echo "$2: Command invoked cannot execute - Permission problem or command is not an executable" >> $file_name
            cmd=`echo $2 | awk '{print $1}'`
            path=`whereis $cmd | awk '{print $2}'`
            echo "\"$path\" has the following permission: `ls -ltr $path | awk '{print $1}'`" >> $file_name
            echo "----> \"$path\" has the following permission: `ls -ltr $path | awk '{print $1}'`" 
    fi
}

printOnFileRichCommandInformation(){
    echo >> $file_name 
    echo >> $file_name 
    echo  “************************************************************ “ >>$file_name 
    echo “************************************************************ “ >>$file_name
    echo “************ Additional information for $1     ************ “ >> $file_name
    echo “************************************************************ “ >>$file_name
}

executeCommands(){
    COMMANDS=$1
    len=${#COMMANDS[*]}
    command=0
    while [ $command -lt $len ]; do
        echo >> $file_name 
        echo "************************************************************" >> $file_name

        if [[ ${COMMANDS[$command]} == lpar* ]];
        then
            printOnFileRichCommandInformation "LPAR"
        fi
        
        if [[ ${COMMANDS[$command]} == nvidia* ]];
            then
                printOnFileRichCommandInformation "GPU NVIDIA"
        fi


        echo “************************************************************ “ >> $file_name
        
        echo "   ${COMMANDS[$command]}"
        echo “bash$ ${COMMANDS[$command]}” >> $file_name
        eval ${COMMANDS[$command]} >> $file_name
        OUT=$?
        if [ $OUT -ne 0 ]; then 
            exitStatusDescription "$OUT" "${COMMANDS[$command]}"
        fi
        command=$((command+1))
    done

}

printHeadFormatInfo(){
    echo
    echo “***************************************************************************** “
    echo "Gathering system information ........"
    echo “*********************************************************** “ > $file_name
    echo “*********     GETTING SYSTEM INFORMATION          ********* “ >> $file_name
    echo “*********************************************************** “ >> $file_name
    echo “***********   OPERATING SYSTEM TYPE:   $OS_TYPE   ************** “ >> $file_name
    echo "*****    Date: `date`    ******" >> $file_name
    echo
}

execute(){
    COMMANDS=$1
    ########################  AIX Operating System ###########################################
    if [ "$OS_TYPE" = "AIX" ]; then
        echo "Operating System: AIX "
        echo "System Information from following commands: "
        executeCommands "${COMMANDS}"

    elif [ "$OS_TYPE" = "SunOS" ]; then
    ########################  SunOS Operating System ###########################################

        echo "Operating System: SunOS"
        echo "System Information from following commands: "
        executeCommands "${COMMANDS}"

    elif [ "$OS_TYPE" = "Linux" ]; then
    ########################  Gnu/Linux Operating System ###########################################
        echo "Operating System: GNU/Linux"
        echo "System Information from following commands: "
        executeCommands "${COMMANDS}"
    fi
}

executeFurtherCommand(){
    set WISH= "y"
    while [ "$WISH" != "n" ] 
    do
        echo “***************************************************************************** “
        echo "Do you wish to gather further information? <y or n>"
        read WISH

        if [ $WISH = "y" ] ; then
           echo >> $file_name 
           echo "************************************************************" >> $file_name
           echo "Please insert the command you would like to execute...."
           read -p '$bash ' COMMAND
           echo “bash$ $COMMAND” >> $file_name
           eval $COMMAND >> $file_name
           OUT=$?
           if [ $OUT -ne 0 ]; then 
            exitStatusDescription "$OUT" "$COMMAND"
           else 
            echo "......command \"$COMMAND\" executed successfully!"
           fi
        fi 

        if [ "$WISH" != "n" ] && [ "$WISH" != "y" ] ; then
           echo "your choice $WISH is incorrect"
        fi

    done
}

printBottomFormatInfo(){
    echo
    echo "........these information are stored on `pwd`/$1"
    echo “***************************************************************************** “
}


###################################################################################################
checkStorageFile "$file_name"

printHeadFormatInfo

getCommandsSpecificOS $OS_TYPE

execute "${COMMANDS}"

printBottomFormatInfo "$file_name"

executeFurtherCommand


echo >> $file_name 
echo >> $file_name 
echo "************************************************************" >> $file_name
echo

# 5  
Old 02-05-2013
Note that the shell you get may not have functions, either.

Instead of arrays, how about strings?

Code:
AIX_COMMANDS='hostname
uname -a
ulimit -a
smctl
swap -l
/etc/prtconf
oslevel –s
lparstat –i
lscfg -vp | grep -ip proc | grep "PROC"
mpstat'

OLDIFS="$IFS"
# Split on newlines and only newlines
IFS="
"

for X in $AIX_COMMANDS
do
        echo "Got command $X"
done

IFS="$OLDIFS"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Please Help ! ----> error: expected ‘=’,

#include<stdio.h> int main{ char *fl; fl=(char*)malloc(150); strcat(fl,"/tmp/OV/"); printf("\nInside fl--->%s\n",fl); return 0; } I wrote a simple program as above. I got the error error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token Please help me out ! I am... (4 Replies)
Discussion started by: gameboy87
4 Replies

2. Programming

Synchronization of threads C. Error: Expected ')' before ';'

Hi, I'm trying to solve an assignement on school where we are supposed to synchronize two threads and write out their ID every other time. I've written down the code for the two threadFunctions which is associated with two threads created in the main function. What I'm trying to achieve... (5 Replies)
Discussion started by: sjallamander
5 Replies

3. Shell Programming and Scripting

Error: integer expression expected

root@server01 # df -h | grep /tmp | awk {'print $3}' 252M root@server01 # root@server01 # cat /usr/local/tmpchk.sh #!/bin/sh x=`df -h | grep /tmp | awk {'print $3}'` if ; then rm -fr /tmp/somefolder/ else echo "its small" (2 Replies)
Discussion started by: fed.linuxgossip
2 Replies

4. Shell Programming and Scripting

integer expected error::please help ...urgent

I have written the following shell script for submitting check to nagios .It was working fine a few hours ago.I don remember what changes i made and its giving integer expression expected error. #!/bin/bash #$PGREP ${SSHD} if ] then echo "ssh down" ... (1 Reply)
Discussion started by: nasir_khan
1 Replies

5. Shell Programming and Scripting

if stmt argument expected error

CT=0 while read LINE do # Check to see if the LINE is non-empty, and has a <td> tag in it. if then # Increase the TD counter by 1 CT=`echo "$CT+1"` fi done <test.htmthrows this error: ksh: test: argument expected test.htm <tr> <td>text</td... (4 Replies)
Discussion started by: dba_frog
4 Replies

6. Shell Programming and Scripting

fi not expected error

I'm trying this script and I keep getting a 'fi' not expected error: #!/bin/sh #TD=0 CT=0 cat P7748 |while read LINE do # Check to see if the LINE is non-empty, and has a <td> tag in it. if # Increase the TD counter by 1 CT=`echo "$CT+1" |bc` ... (2 Replies)
Discussion started by: dba_frog
2 Replies

7. Shell Programming and Scripting

Receiving error: ./ang.ksh[35]: 0403-057 Syntax error at line 116 : `done' is not expected.

Hi All I am quite new to Unix. Following is a shell script that i have written and getting the subject mentioned error. #!/bin/ksh #------------------------------------------------------------------------- # File: ang_stdnld.ksh # # Desc: UNIX shell script to extract Store information.... (3 Replies)
Discussion started by: amitsinha
3 Replies

8. Shell Programming and Scripting

ERROR: ./launch_full_backup.sh[18]: Syntax error at line 28 : `else' is not expected.

Help please! :confused: I have the following error with the following file and the emails are not arriving to the email, any idea please? ERROR: ./launch_full_backup.sh: Syntax error at line 28 : `else' is not expected. FECHA=`date +%d%m%y%H%M`... (2 Replies)
Discussion started by: villenan
2 Replies

9. Shell Programming and Scripting

binary operator expected error

It is erroring for : binary operator expected on the if line. Any suggestions? Thanks in advence. (7 Replies)
Discussion started by: apps_user
7 Replies

10. Shell Programming and Scripting

arguments expected error

ive implemented getopt for the command line but have this problem, #!/bin/sh text="" set -- getopt "t" etc .... #sets arguments while : do case "$1" in #gets arguments -t: shift; text="$1" ;; shift done shift if then echo "no text" else echo... (4 Replies)
Discussion started by: strike
4 Replies
Login or Register to Ask a Question