KSH, FTP running a set number at a time?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH, FTP running a set number at a time?
# 1  
Old 08-13-2008
Question KSH, FTP running a set number at a time?

At work we have a script that pulls a file from a list of remote sites every 10 min. Currently it only does this ftp one sites at a time and this process takes up to 8 minutes to complete. I want to have this list of 24 sites and be able to run the ftp from up to 2 sites on the list at a time. I don't want to do it in chunks of 2 but a free flowing limit of 2. I am just at a mental block right now and looking for a push to help me figure this out. This is a ksh script on an AIX machine. So an example of what is currently being done is below. This will run the cust1 and then when finished go and do cust2. I would like to run cust1 and then while that is running start cust2 and then wait until either 1 or 2 is finished and then start cust3......and so on.

#!/usr/bin/ksh

SAMPLE ()
{
cd $HOME_DIR
rm $SITE >/dev/null 2>/dev/null
ftp -i -n -v $IP >>$FTP_DIR/ftp_log 2>>$FTP_DIR/ftp_log <<HERE
user $CUST $PASSWD
cd $SITE_DIR
bin
get ${SITE}
bye
HERE
}

#CUST1
SITE=home1
IP=192.168.1.1
CUST=Guy1
PASSWD=12345
SAMPLE

#CUST2
SITE=home2
IP=192.168.1.2
CUST=Guy2
PASSWD=12345
SAMPLE

#CUST3
SITE=home3
IP=192.168.1.3
CUST=Guy3
PASSWD=12345
SAMPLE


I was thinking that I could make a counter that +/- when a ftp is started and finished and a loop that would check this and keep going unti lmy list has been completed. I think the part that is confusing me the most is how to get a ksh script to run this SAMPLE function 2 times and once completed start the next on the list. Any ideas or suggestions to help me figure this out?
# 2  
Old 08-13-2008
Here is a code I did that regulates the flow of programs running to 4

You should be able to modify as you need

Code:
while read LINE                          # go through the output file from the view one line at a time
do

     export SRC_FILE_ID=$(echo $LINE | cut -f 1 -d \|)
     export SRC_FILE_TYPE=$(echo $LINE | cut -f 2 -d \|)
     export INBOUND_DIR=$(echo $LINE | cut -f 3 -d \|)
     export FILENAME=$(echo $LINE | cut -f 4 -d \|)
     export XTB_TB_NAME=$(echo $LINE | cut -f 5 -d \|)
     export REGEXP=$(echo $LINE | cut -f 6 -d \|)



     echo_f ""
     echo_f 'SRC_FILE_ID:      ' $SRC_FILE_ID
     echo_f 'SRC_FILE_TYPE:    ' $SRC_FILE_TYPE
     echo_f 'INBOUND_DIR:      ' $INBOUND_DIR
     echo_f 'FILENAME:         ' $FILENAME
     echo_f 'XTB_TB_NAME:      ' $XTB_TB_NAME
     echo_f 'REGEXP:           ' "$REGEXP"


    if [[ ! -r $INBOUND_DIR/$FILENAME ]]  # if the file does not exist, go to next one
    then
       echo_f $INBOUND_DIR/$FILENAME not found at $(date)
       echo_f skipping this processing
       continue;
    fi

   case $(echo $SRC_FILE_TYPE | cut -c -1) in
         M)    export PACKAGE="PKG_DW_CLM_LOAD";;
         P)    export PACKAGE="PKG_DW_CLMRX_LOAD";;
   esac


    # getting here, we want to submit the job to run, up to the limit of 4 jobs running at one time
    # See if there are 4 jobs running right now
      while [[ $( jobs | wc -l ) -ge 4 ]]
      do
        echo_f going to sleep now at $(date)
        sleep 30
      done

      /avidyn/scripts/avd_runit_002.ksh 1>/dev/null 2>&1 &   # parameters are passed by the export statements

done < /avidyn/tmp/avd_runit_001_jobs_to_run.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh - variable to be set to windows path issue

Greetings Experts, I need to pass a parameter to ksh and the value is windows path eg: sh abc.txt C:\Users\chill3chee\Desktop No matter I try with \ delimiter, still could not get this exact value assigned to the shell variable which was checked with echo. Tried with using... (2 Replies)
Discussion started by: chill3chee
2 Replies

2. Shell Programming and Scripting

Help with sort word followed by exponential number and numeric number at the same time

Input file: ID_34 2E-69 2324 ID_1 0E0 3254 ID_1 0E0 5434 ID_5 0E0 436 ID_1 1E-14 2524 ID_1 5E-52 46437 ID_3 65E-20 45467 ID_1 0E0 6578 ... Desired output file: ID_1 0E0 6578 ID_1 0E0 5434 ID_1 0E0 3254 ID_1 5E-52 46437 ID_1 1E-14 2524 ID_3 65E-20 45467 (5 Replies)
Discussion started by: cpp_beginner
5 Replies

3. Shell Programming and Scripting

Unable to set PATH through ksh shell

I'm trying to set path for the current session but it is not doing so. It works perfectly on command line though. #!/usr/bin/ksh PATH=$PATH:/opt/quest/bin Is there any specific way to set path on korn? (3 Replies)
Discussion started by: pjeedu2247
3 Replies

4. Shell Programming and Scripting

set ksh script in restricted mode

Hi, I came across a post wherein you can use "set -r"(on bash) to activate restricted mode ( wherein you cant run some commands such as cd etc). Can anyone guide if we have anything similar in ksh ? Thanks (2 Replies)
Discussion started by: Shivdatta
2 Replies

5. Shell Programming and Scripting

Ftp script hangs for first time,but works every second time

Hi I have an ftp script which works fine when i execute through a test scheduler(UC4), but when i run it through the prod scheduler(UC4), it hungs indefinetely, when we cancel the job and re-run it it works perfectly fine. here is the code,, any idea why this is happening ???? ... (1 Reply)
Discussion started by: selvankj
1 Replies

6. Shell Programming and Scripting

KSH script eval(?) to set variable

first of all, thanks to all on this board, it has been a huge resource to answer most of my questions! I am stuck on something that should really be simple, and was looking for some help.. I am using KSH on solaris and working on a script to move containers from server to server. Where i am... (4 Replies)
Discussion started by: tksol
4 Replies

7. Shell Programming and Scripting

Running a queued set of commands?

Is there a way I can queue something like 800 commands in a BASH (or anything else for that matter) script? I just basically don't want to have 800 commands pound my system at once. So far I have been just running the list (dynamically generated) through a loop, and executing every command in... (1 Reply)
Discussion started by: jjinno
1 Replies

8. Shell Programming and Scripting

set Working day in ksh

Hello guys it´s a pleasure to type with the unix community...I´m new in shell script and I need to insert into a #!/ksh a statment that will check if a file that I´ll receive from another script is arriving in the first working day of each month: let´s say that I´ll reveive the following files... (1 Reply)
Discussion started by: Rafael.Buria
1 Replies

9. Shell Programming and Scripting

ksh: dbfFILe: parameter not set

Having the following message returned: FIND REDLOG FILES..... ksh: dbfFILe: parameter not set When I attempt to perform the script below....#!/bin/ksh . $HOME/.profile # Initial Script Prerequisites ORACLE_SID=MDirect ; export ORACLE_SID REDOLOGDIR=$ARCLOGDEST ; export REDOLOGDIR... (2 Replies)
Discussion started by: Cameron
2 Replies

10. Shell Programming and Scripting

problem with set -A in ksh

I am trying to load a file into an array by using the set -A command in the ksh. The file contains a comma delimited record of 19 fields and is 5196 records long. If I execute the following command, I get the record count. cut -f1-19 -d',' -s RAGEFF.lst|sed 's/,/ /g'|sed 's/\L//g'|nawk '{ if... (2 Replies)
Discussion started by: beilstwh
2 Replies
Login or Register to Ask a Question