Error with korn shell - arrays


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error with korn shell - arrays
# 1  
Old 08-21-2008
Question Error with korn shell - arrays

Hi All

I have a FTP script which FTPs few files into an user folder. I intend to keep track of the folder size before FTP and after FTP and print that once the FTP script is run (a kind of comparison, "Before FTP, "After FTP").

I decided to use kron shells to accomplish this.
Code:
#! /bin/ksh

analyse_folders_pre() {

 # List of directories to check.
 dirNames[0]='bin'
 dirPath[0]='/home/user1/bin'
 dirNoFilesPre[0]=$(ls  ${dirPath[0]} | wc -l | awk '{print $1}')

 idx=0
 while [ $idx -ne 1 ]
 do
    tempSize=0
    dirFileSizePre[$idx]=0
    dirSize=0

    for i in $(ls ${dirPath[0]})
    do
      tempSize=$( ls -l $i | awk '{print $5}')
      ((dirSize=dirSize+tempSize))
    done
    dirFileSizePre[$idx]=$dirSize
    ((idx = idx+1))
 done

} ### End of analyse_pack_rel_pre

 ### Main Script Starts here ###
 # List of directories to check.
 dirNames[0]='bin'
 export dirNames

 dirPath[0]=''
 export dirPath

 dirNoFilesPre[0]=0
 export  dirNoFilesPre

 dirNoFilesPost[0]=0
 export  dirNoFilesPost

 analyse_folders_pre 

 ### Script to FTP
 ftp_files

 analyse_folders_post

 i=0
 while [ $i -ne 1 ]
 do
  echo ${dirNoFilesPre[$i]}
  echo ${dirFileSizePre[$i]}

  echo ${dirNoFilesPost[$i]}
  echo ${dirFileSizePost[$i]}
  ((i=i+1))
 done

But, I am getting the following error.
syntax error at line 8: `dirNoFilesPre[0]=$' unexpected

What might be wrong? Is there any better way to do it?
# 2  
Old 08-21-2008
Quote:
dirNoFilesPre[0]=$(ls ${dirPath[0]} | wc -l | awk '{print $1}')

try doing this..

Quote:
dirNoFilesPre[0]=$(`ls ${dirPath[0]} | wc -l | awk '{print $1}'`)
# 3  
Old 08-21-2008
Same error

Still getting the same error. . .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Not able to capture sftp error in Korn Shell

I am not able to capture error condition in sftp in Korn Shell #!/bin/ksh sftp batch@uat >abc 2>&1 << ENDFILE cd public put /data/WELCOME_55 ENDFILE ret_val=$? if ] then print file "copied successfully" else print file "NOT copied successfully" fi return 0 Now the... (9 Replies)
Discussion started by: Soham
9 Replies

2. Shell Programming and Scripting

Change text color in Korn shell to highlight Error

Hi this is my first post, so forgive me if what I'm requesting doesn't make sense. I'm connecting into a Unix server via SSH and using a Korn Shell (#!/bin/ksh). The Unix server has Oracle 11g installed on it and there are a number of scripts already setup to query the Oracle database to perform... (2 Replies)
Discussion started by: KeithJ
2 Replies

3. Shell Programming and Scripting

Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. $ echo $SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 Replies

4. Shell Programming and Scripting

korn shell script executed with error

Hi, need help, I would like to know what is this IF statement trying to do? When the script is executing and error out with line 9 which is the IF statement line. if ] then TOPDIR=$(pwd) else TOPDIR=${0%/*} fi TOPDIR=${TOPDIR%/*} the log file. Current system time is... (15 Replies)
Discussion started by: beooi
15 Replies

5. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

6. Shell Programming and Scripting

Korn Shell Script to find out error in logfile

Hi All, I am new to this forum as well as to unix scripting. Can you please help me to create a korn shell script to find out errors in logfiles and get the name of that logfile ( which is having error) in email and email it to me? (2 Replies)
Discussion started by: jithu
2 Replies

7. Shell Programming and Scripting

how to convert from korn shell to normal shell with this code?

well i have this code here..and it works fine in kornshell.. #!/bin/ksh home=c:/..../ input=$1 sed '1,3d' $input > $1.out line="" cat $1.out | while read a do line="$line $a" done echo $line > $1 rm $1.out however...now i want it just in normal sh mode..how to convert this?... (21 Replies)
Discussion started by: forevercalz
21 Replies

8. UNIX for Advanced & Expert Users

Error Handling in Korn Shell scripts

Hi, I am using few ISQL statements to update and delete from a few tables in sybase, now i want to roll back the transaction when any of the statements fail.How i can i capture these errors in the shell scripts.Please advise. Thanks, Gopi (4 Replies)
Discussion started by: bhgopi
4 Replies

9. Shell Programming and Scripting

KORN Shell - Spawn new shell with commands

I want to be able to run a script on one server, that will spawn another shell which runs some commands on another server.. I have seen some code that may help - but I cant get it working as below: spawn /usr/bin/ksh send "telnet x <port_no>\r" expect "Enter command: " send "LOGIN:x:x;... (2 Replies)
Discussion started by: frustrated1
2 Replies

10. Shell Programming and Scripting

korn shell "loops & arrays"

Hi, I am trying to write a script which will loop until a certain action has been performed. I have two files i would like to compares. For example: file1 has a list of user ids (about 900) from the company's e-mail server. file2 has a list of user ids (about 50 or so) from... (7 Replies)
Discussion started by: muzica
7 Replies
Login or Register to Ask a Question