Not the usual ftp script question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Not the usual ftp script question
# 1  
Old 04-26-2005
Not the usual ftp script question

I have an order file that gets updated periodically on a ftp server.
The file format is "number one-day of the quarter-file number". For example,
the format would look like this for today and would increment as such.

1-26-1
1-26-2
1-26-3
etc

After I grab each oder file, I will rename it 1-26-1.done, 1-26-2.done, 1-26-3.done, and so on.

My qusetion is how to grab an order file, rename it to done, then when the script runs again, pull the next sequential file without touching the done file.

Also, if there are multiple new order files, how can I grab multiple files and rename them during one interactive ftp session.

Any help would be greatly appreciated.
# 2  
Old 04-26-2005
The following script doesn't match your problem exactly as I was using ssh/scp with RSA key equivalency between the hosts, but it should illustrate a possible method.

Code:
for i in `ssh -p 22 user@host find /some/path/to/files/ -name ! *.done -mmin +1`; do
        /usr/local/bin/scp -P 22 user@host:$i /where/I/want/the/files
        /usr/local/bin/ssh -p 22 user@host mv -f $i ${i}.done
done

The same idea could be extened into a script with ftp.

Cheers,

Keith
# 3  
Old 04-26-2005
Thank you for the response. This would be easy if the ftp server wasn't Windows; however, the ftp server is windows, and the ftp script is running from a unix server using the bash shell.
# 4  
Old 04-26-2005
You should consider switching to ksh. This would be easy with a co-process.
# 5  
Old 04-26-2005
Perderabo,

I can use ksh. Would you mind giving me an idea of how I might accomplish this task
using ksh. Your help would be greatly appreciated.

Right now I am stuck with building a file transfer list based on a numeric ext. that can be in the range of 1-99999. The I am using wget with the no clobber option to execute a loop based on the build list. I still couldn't figure out how to rename randomly generated files, which have been transferred, with a numeric "ext." to ".done"

There has to be an easier way.
# 6  
Old 04-26-2005
There is a problem here. The script is flying blind. You have to tune the sleep command to ensure that the script sleeps until after the file arrives. And the script uses my datecalc script.
Code:
#! /usr/bin/ksh

date '+%Y %m %d' | read year month day
today=$(datecalc -j $year $month $day)


#
#       compute start of quarter

((quarter_month=(month-1)/3*3+1))
echo quarter_month = $quarter_month
quarter_start=$(datecalc -j $year $quarter_month 1)
((day_of_quarter=today - quarter_start +1))
echo day_of_quarter = $day_of_quarter


#
#       Set up ftp co-process
HOST=aaaa.bbbb.com
USER=dhdhdh
PASSWD=shshsh

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD

#
#       Loop on filename
num=0
looping=1
while ((looping)) ; do
        ((num=num+1))
        file=1-${day_of_quarter}-$num
        if [[ ! -f $file ]] ; then
                echo file = $file
                print -p get $file
                sleep 5  #  wait for file to arrive
                if [[ -f $file ]] ; then
                        print -p rename $file ${file}.done
                else
                        looping=0
                fi
        fi
done

print -p bye

wait
exit 0

# 7  
Old 04-27-2005
Perderabo,

Thank you for the script. I am still a novice at shell scripting, so please bear with me. I tried running the script, and I received the following errors. Is this datecalc another script or builtin ksh function ?

./ftptest1.ksh
./ftptest1.ksh[4]: datecalc: not found
./ftptest1.ksh[13]: day_of_quarter=today - quarter_start +1: bad number
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Solaris

Copy via samba on vmware workstation with Solaris taking much longer than usual

i have a vmware workstation with solaris 10 installed on this. i copying 2 gb data via samba from windows to this vmware workstation. copy speed is 24 kb/sec. how i can speed up this copy process ? (7 Replies)
Discussion started by: rehantayyab82
7 Replies

2. Shell Programming and Scripting

repeating ftp script question

so i got this request to do this: - Script should check for the file ever 15 minutes on the FTP server…if the file is not found, then the whole script exits. File will only be created one a week at random. i have gotten this far, but am kind of stuck, also sleep command doesnt work... (3 Replies)
Discussion started by: zapatur23
3 Replies

3. Programming

Java double subtraction oddity (not the usual rounding discrepancy)

I've been going through a java tutorial, and ran across some strangeness in this small example... class SqrRoot { public static void main(String args) { double num,sroot,rerr,resquare; for(num = 1.0; num < 100.0; num++) { sroot = Math.sqrt(num); ... (1 Reply)
Discussion started by: Trones
1 Replies

4. Shell Programming and Scripting

Automated FTP script using .netrc to multiple FTP servers

Hi all, I'm using the following script to automated ftp files to 1 ftp servers host=192.168.0.1 /usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp open $host bin cd ${directory} put $files quit ftp and the .netrc file contain machine 192.168.0.1 login abc... (4 Replies)
Discussion started by: varu0612
4 Replies

5. Shell Programming and Scripting

perl or bash script that will generate a higher than usual load

Hi, please advise what function in perl or system call in shell that will generate cpu usage that is higher than usual? I would like make such a script, to test a monitoring feature. TIA. Marc (1 Reply)
Discussion started by: marcpascual
1 Replies

6. Shell Programming and Scripting

FTP - shell script question

Hi All, I had a question on something which i have trying to add to my current shell script which does FTP of files from my local machine to a remote server. I have 5 files which i zip and FTP them on daily basis to a remote server. My script is as below: ############################... (6 Replies)
Discussion started by: bsandeep_80
6 Replies
Login or Register to Ask a Question