Korn Shell programming (FTP, LOOPS, GREP)

Hello All,

I have another Korn shell question. I am writing a script that will ftp a file from my production database to my test database.

To this, I have to construct a loop that checks a specified folder for a file.
If the file exists, I want it execute the ftp protocol and then exit.

If it does not see the file, I want it loop 9 times and sleep for 70 seconds at the end of every loop.
Once the 9 loop happens, I want a specified statement to given then exit out of the entire process.

As the below code illustrates I am using an �if� statement within a while loop to accomplish this task.
In addition, in order to establish where the file exists in the specified directory, I created a variable that uses a grep -c "phrase" to which will give me 0 or 1.

The issue that I am having is that my grep command is passing me an error stating

ftp_ddw0.ksh[31]: grep -c stat_load /home/dkjones/dim009/load: 0403-009 The specified number is not valid for this command.

I have tested the command from the command line and it gives me a numerical value.
I do not know what is causing the problem. Any assistance that you can give would be appreciated.

I am just learning Korn shell programming so my grasp of the syntax is very limited. The code is as follows:

myftplog="$FTP_LOG_DIR_DDW0/ftplogfile"
ftpfile="$HOST_LOAD_DIR_DDWO/run_exp.load"
loadstat="$LOAD_STATUS_DIR/stat_load_configi"
loadstatcnt=0
ldcount="grep -c "stat_load" $LOAD_STATUS_DIR"
while [[ $loadstatcnt -le 9 ]]; do
  echo "$(date "+%H:%M:%S") -Atempt to check the status of $loadstat file" > $myftplog
  ((loadstatcnt+=1))
  if [[ $ldcount -eq 0 ]]
  then
    echo "$(date "+%H:%M:%S") - Attempting to FTP $ftpfile to $REMOTE_LOAD_DIR_DDW0" > $myftplog
    ftp -v $FTPHOST_DDWTST0 <<EOF >> $myftplog
    cd $REMOTE_LOAD_DIR_DDWTST0
    put $ftpfile
    ls
    quit
    EOF
    exit
  elif [[ $loadstatcnt -eq 9 ]] then echo "Try back later exp.load file is still awaiting to be loaded" exit
  else sleep 70
  fi
done
exit

error message

ftp_ddw0.ksh[31]: grep -c stat_load /home/dkjones/dim009/load: 0403-009 The specified number is not valid for this command.

It may be a problem with your quoting.

ldcount="grep -c "stat_load" $LOAD_STATUS_DIR"

You have nested double quotes..

I think you want something like:

ldcount="grep -c stat_load $LOAD_STATUS_DIR"

If you don't want the inner double quotes to be evaluated, u need to use single quotes, or escape the double quote.

One thing to learn is if you use single quotes, special characters will not be evaluated. If you use double quotes, then special chars will be evaluated. Single quotes are used to hide the meaning of special characters like $, *, \, !, ", ` and /. Any characters between single quotes, except another single quote, are displayed without interpretation

ldcount=`grep -c "stat_load" $LOAD_STATUS_DIR`

use backsticks