Korn Shell programming (FTP, LOOPS, GREP)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Korn Shell programming (FTP, LOOPS, GREP)
# 1  
Old 02-10-2010
Error 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


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

Code:
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
Code:
ftp_ddw0.ksh[31]: grep -c stat_load /home/dkjones/dim009/load: 0403-009 The specified number is not valid for this command.


Last edited by Franklin52; 02-10-2010 at 03:15 PM.. Reason: Please indent your code and use code tags!!
# 2  
Old 02-10-2010
It may be a problem with your quoting.
Code:
ldcount="grep -c "stat_load" $LOAD_STATUS_DIR"

You have nested double quotes..

I think you want something like:
Code:
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
# 3  
Old 02-10-2010
Code:
ldcount=`grep -c "stat_load" $LOAD_STATUS_DIR`

use backsticks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Alternative solution to nested loops in shell programming

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hi, The problem statement is: I am trying to read line by line from a flat file by using a while loop. The... (9 Replies)
Discussion started by: Sandeep Pattnai
9 Replies

2. Shell Programming and Scripting

korn shell for loops with expect issue

Hi I have the following Korn script having multiple for loops. #!/bin/ksh EXPECT=/usr/local/bin/expect exp_internal for d in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 i22 23 24 25 26; do for i in 01 02 03 04 05 06 07 ; do for h in 00 01 02 03 04 05 06 07 08 09 10 11 12... (2 Replies)
Discussion started by: cic
2 Replies

3. Shell Programming and Scripting

korn shell and Web Development

Hi , I might be asking a silly question but I just wonder if I can design/create my webpages using korn Shell or bash instead or using perl or php.This webpages I want to create are basically to perform admin work. With Perl the limitation for me is the fact of having to compile and install... (1 Reply)
Discussion started by: arizah
1 Replies

4. AIX

AIX 4.2 Korn shell and grep question

Ho do I find out the verion of the Kron shell on my client`s system ? There is no one to ask. They are not knowledged enough (hard to believe but yes). Also, on that AIX 4.2, I am trying to figure out how to do a grep using a search patter like below but does not seam to work. The '*' do... (11 Replies)
Discussion started by: Browser_ice
11 Replies

5. AIX

how to check the existence of a file during ftp using korn shell?

i can able to transfer a file from build server(AIX)to webserver using ksh through ftp.my query is to check the existence of file while transfering from one server to other .i.e i need some command or script that checks the existence of file with same name in both server,within ftp syntax. ... (1 Reply)
Discussion started by: karthikprasathk
1 Replies

6. UNIX for Dummies Questions & Answers

find and FTP multiple files in Korn Shell

I want to FTP multiple files in a directory that the files were created since midnight of the same day using korn shell. I can use the "find" command using -newer arguement that compares against a time stamp file. The script identifies the files, I can't use a variable = `find . ` as the... (2 Replies)
Discussion started by: lambjam
2 Replies

7. Shell Programming and Scripting

Loops within ftp shell session

Hi guys, i need to script the sending of multiple files through one ftp session. I have done this so far: ---------------------------------------------------------------- #!/bin/sh USER=myuser PASSWD=mypass filenum=$1 x=0 ftp -n 159.167.95.199 <<SCRIPT user $USER $PASSWD binary while ... (4 Replies)
Discussion started by: zaff
4 Replies

8. Shell Programming and Scripting

KORN SHELL PROGRAMMING BY EXAMPLE book

Hi all, can any tell if we can get Indian edition of korn shell programming by example by O'brain from QUE publications. I tried to and did not find. If any one is having the infi then pls let me know. thanks in advance. ksrsarma (0 Replies)
Discussion started by: ksrsarma
0 Replies

9. 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

10. Shell Programming and Scripting

using FTP related commands in nawk utility in shell programming

I am facing problem while accesing FTP related commands in nawk code in bourne shell programming.I can able to connect to remote machine, but i can't able to get files from that machine. Please help me in this.If you send code along with the solution, then it will be usefull for me. (4 Replies)
Discussion started by: nrsekhar
4 Replies
Login or Register to Ask a Question