Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-30-2013
ooilinlove's Avatar
Registered User
 
Join Date: Aug 2008
Posts: 67
Thanks: 7
Thanked 0 Times in 0 Posts
My script work on Linux but not work in sunos.

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

my script.


Code:
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.

Code:
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'

Sponsored Links
    #2  
Old 01-30-2013
panyam panyam is offline Forum Advisor  
Registered User
 
Join Date: Sep 2008
Posts: 1,138
Thanks: 20
Thanked 101 Times in 96 Posts
Which Shell are you using in Linux and in Unix?

It depends on the shell.
Sponsored Links
    #3  
Old 01-30-2013
zazzybob's Avatar
Registered Geek
 
Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,186
Thanks: 3
Thanked 23 Times in 22 Posts
Add a shebang to the top

Code:
#!/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 ).
    #4  
Old 01-30-2013
ooilinlove's Avatar
Registered User
 
Join Date: Aug 2008
Posts: 67
Thanks: 7
Thanked 0 Times in 0 Posts
sun = /bin/ksh
linux = /bin/ksh
Sponsored Links
    #5  
Old 01-30-2013
zazzybob's Avatar
Registered Geek
 
Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,186
Thanks: 3
Thanked 23 Times in 22 Posts
Quote:
Originally Posted by ooilinlove View Post
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
Sponsored Links
    #6  
Old 01-30-2013
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,350
Thanks: 144
Thanked 1,756 Times in 1,593 Posts
This is not valid syntax in any shell:

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

Sponsored Links
    #7  
Old 01-30-2013
ooilinlove's Avatar
Registered User
 
Join Date: Aug 2008
Posts: 67
Thanks: 7
Thanked 0 Times in 0 Posts
i try it.
but not work.

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


Code:
SunOS Proton 5.8 Generic_Virtual sun4u sparc SUNW,SPARC-Enterprise


Code:
#!/usr/bin/ksh

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

Code:
#!/usr/bin/sh

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

Code:
#!/usr/bin/bash

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[?] Does Netflix work on Linux in Firefox? KenJackson What's on Your Mind? 4 03-22-2012 08:58 PM
Help gettgin this script to work on linux binary-ninja Shell Programming and Scripting 4 08-23-2011 11:24 AM
Script doesn't work, but commands inside work cheongww UNIX for Dummies Questions & Answers 2 11-14-2006 09:52 PM
Work on Linux Using Bootable CD ?? newbie07 UNIX for Dummies Questions & Answers 2 04-25-2006 12:48 AM
ISDN on Linux..will it work? Phaelanx UNIX for Dummies Questions & Answers 4 03-01-2002 11:59 AM



All times are GMT -4. The time now is 02:23 AM.