Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 435
  • Last Modified:

Bash shell to Korne shell problem

I have a BASH shell I have written for Linux and Solaris and it works a treat.  Now however the requirements have changed and I need to bring it over to AIX as well (thanks boss!!).  KSH seems to be the way forward and I can start to alias various commands when needed, however I have a strange syntax problem with the current script.

Full Script is below.  Basically it sets up the env, finds a specific file in the directory structure and loads the location into an array, it then searches through each file looking to ensure both cases don't feature a specific string (incrementing by one each of them) so if the number is more than zero it says its compliant in the report (or not).

The following error is recieved.
./sample.sh[17]: syntax error: `(' unexpected

How do I cater for this and get the functionality I require from the other platforms under KSH? Thanks in advance.

#!/bin/ksh
# Name: Audit Requirements
 
# Env Setup
export SCRIPTVER="0.1"
export SEARCHFOREXT="ibm-web-ext.xmi"
export SEARCHROOT="/opt"
export MYNAME=`uname -n | cut -f1 -d.`
 
# Search for File from a root and place in an Array
AUDITEXTARRAY=(`find $SEARCHROOT -name $SEARCHFOREXT 2>/dev/null`)
 
# Loop to investigate compliance
num=0
while [[ ${#AUDITEXTARRAY[*]} != $num ]]
 do
        AUDITCOMPFOUND=0
        AUDITCOMPFOUND=$(grep -c -i "serveServletsByClassnameEnabled=\"true\"" ${AUDITEXTARRAY[$num]})
        let AUDITCOMPFOUND+=$(grep -c -i "fileServingEnabled=\"true\"" ${AUDITEXTARRAY[$num]})
        if [ $AUDITCOMPFOUND != 0 ]
                then
                        echo $MYNAME,"Non-compliant",${AUDITEXTARRAY[$num]}
                else
                        echo $MYNAME,"Compliant",${AUDITEXTARRAY[$num]}
        fi
        let num+=1
done
 
# Report at End
echo
echo Total amount of Files is $num

0
london_mccourt
Asked:
london_mccourt
  • 2
  • 2
  • 2
  • +3
3 Solutions
 
cruxyCommented:
AUDITEXTARRAY=(`find $SEARCHROOT -name $SEARCHFOREXT 2>/dev/null`)

isn't there a $ missing before (`find ?
0
 
london_mccourtAuthor Commented:
That appears to have fixed that issue but now it has problems on Line 33

Which is basically the While statement.  I'd bet its something to do with the following statement.

        AUDITCOMPFOUND=$(grep -c -i "serveServletsByClassnameEnabled=\"true\"" ${AUDITEXTARRAY[$num]})
        let AUDITCOMPFOUND+=$(grep -c -i "fileServingEnabled=\"true\"" ${AUDITEXTARRAY[$num]})

0
 
ozoCommented:
It seems to be working for me as is
Are you sure you're running it under ksh?
is the
#!
the first two characters in the file?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
cruxyCommented:
could you please post the full error message?
0
 
aaron757Commented:
You are not executing the grep with ` like you are with the find.
0
 
ostwaldlCommented:
Is it possible for you just to install bash on the AIX server?  There is a version of bash available in the toolbox listed below on the IBM website (for AIX 5L).  

This way you won't have to rewrite this (or other) scripts.

http://www-03.ibm.com/servers/aix/products/aixos/linux/download.html
0
 
london_mccourtAuthor Commented:
I think I'm onto something here.

export AUDITEXTARRAY=$(find $SEARCHROOT -name $SEARCHFOREXT 2>/dev/null)

When I look in this array, when executed under KSH there is only one item in the array whereas there should be more.  I must be loading the items into the array wrong.

Putting Bash on is not going to happen here unfortunatly :o(
0
 
ozoCommented:
for v in  $(find $SEARCHROOT -name $SEARCHFOREXT 2>/dev/null) ;do AUDITEXTARRAY[${#AUDITEXTARRAY[*]}]=$v  ; done
0
 
TintinCommented:
That all seems a very complicated way of just doing:

#!/bin/ksh
# Name: Audit Requirements

# Env Setup
SCRIPTVER="0.1"
SEARCHFOREXT="ibm-web-ext.xmi"
SEARCHROOT="/opt"
MYNAME=`uname -n | cut -f1 -d.`

let num=0

AUDITCOMPFOUND=0

for file in $(find $SEARCHROOT -name $SEARCHFOREXT 2>/dev/null)
do
  AUDITCOMPFOUND=$(egrep -c -i "serveServletsByClassnameEnabled=\"true\"|fileServingEnabled=\"true\"" $file)

  if [ $AUDITCOMPFOUND != 0 ]
  then
     echo "$MYNAME,Non-compliant,$file"
  else
     echo "$MYNAME,Compliant,$file"
  fi

 let num+=1

done

# Report at End
echo
echo Total amount of Files is $num

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now