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.