My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os.

my script.

logFiles="sentLog1.log sentLog2.log"
intial_time="0 0"
logLocation="/usr/local/tomcat/logs/"
sleepTime=600


failMessage=":: $(tput bold)Log not update$(tput rmso) = "
successMessage="OK"

arr=($logFiles)
time_arr=($intial_time)
arrlen=${#arr[@]}
arrcount=()



date
for count=0; count<arrlen; count++ ; do
    arrcount[$count]=`ls -l  $logLocation${arr[$count]}  |awk '{print $5}'`
    echo "${arr[$count]} Original size :: ${arrcount[$count]}"
done
echo

while [ "e" == "e" ] ; do 
    sleep $sleepTime
    date

    for ((count=0; count<arrlen; count++)) ; do
        nc=`ls -l  $logLocation${arr[$count]}  |awk '{print $5}'`
        echo -n "${arr[$count]} "
        if [ $nc == ${arrcount[$count]} ] ; then
         time_arr[$count]=`echo ${time_arr[$count]} + 10 | bc`       
            echo $failMessage " " ${time_arr[$count]} " Minute."
        else
            arrcount[$count]=$nc
            echo $successMessage
   time_arr[$count]=0
        fi
    done
    echo
 echo
 echo
 echo
done

run on linux it ok. but run on sun os it not ok.

output of sun os.

Wed Jan 30 17:08:28 USA 2013
./MonSellVASMDB.sh: line 18: syntax error near unexpected token `(('
./MonSellVASMDB.sh: line 18: `for ((count=0; count<arrlen; count++)) ; do'

Which Shell are you using in Linux and in Unix?

It depends on the shell.

Add a shebang to the top

#!/bin/bash

and it should work under (most recent) versions of Solaris.

You haven't specified an interpreter, so it'll default to using /bin/sh - fine for Linux ( /bin/sh is usually a symlink to /bin/bash ) but not SunOS where /bin/sh is the Bourne shell or Korn Shell depending on version (Solaris 11 has a symlink to ksh93 ).

sun = /bin/ksh
linux = /bin/ksh

Hi,

Did you try adding #!/bin/bash to the top of your script when running under Solaris, and trying again?

Whilst your shell may be /bin/ksh , that's not what is necessarily interpreting your script unless you explicitly state your interpreter with a shebang.

Cheers,
ZB

This is not valid syntax in any shell:

for count=0; count<arrlen; count++ ; do

i try it.
but not work.

---------- Post updated at 06:16 PM ---------- Previous update was at 06:11 PM ----------

SunOS Proton 5.8 Generic_Virtual sun4u sparc SUNW,SPARC-Enterprise
#!/usr/bin/ksh

error : syntax error at line 12: `arr=' unexpected

#!/usr/bin/sh

error : syntax error at line 12: `arr=' unexpected

#!/usr/bin/bash

error : syntax error near unexpected token `(('
: line 20: `for ((count=0; count<arrlen; count++)) ; do'

Did you correct the invalid syntax I mentioned? You could also try:

#!/usr/dt/bin/dtksh