repeating ftp script question

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting repeating ftp script question
# 1  
Old 09-21-2011
Java 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 in ftp, so looking for the right statement to use (if, then, else, while, etc.) or should it just be done with a cron?, here's what i have so far, until i get stuck:


ftp -n $HOST <<EOF
quote USER $USER

(this is the part i'm struggling withSmilie

if [[ -f $FILE  ]]; then
get $FILE
   sleep 900

Last edited by Franklin52; 09-22-2011 at 03:20 AM.. Reason: Please use code tags, thank you
# 2  
Old 09-21-2011
Can you install software on the machine doing the fetching?

If so ncftp makes this pretty ncftpget does most of the work for you and gives a nice exit status:

0. Success.
1. Could not connect to remote host.
2. Could not connect to remote host - timed out.
3. Transfer failed.
4. Transfer failed - timed out.

So you can just run:
    ncftpget -u $USER -p $PASSWD ftp://$FILE
    case $? in
        0) echo "All done"
        3) echo "File not there yet"
        4) echo "Network timeout"

I'd suggest running a script every 15 mins via cron, that checks for the local file and if it hasn't already been fetched it then attempts ncftpget.
It's also worth considering using the ncftpget -DD option to remove the remote file once you have it.
This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 09-21-2011
ftp allows to direct output from its command, say ls, to the shell.

As example:
ftp -i my.ftp.server << EOF
cd $my/path
ls $my.file "|wc -l > temp.file"

This piece will place 1 into temp.file if file $my.file exists, otherwise you will get 0

You can make decision in your script based on that 1 or 0

Last edited by migurus; 09-21-2011 at 10:10 PM.. Reason: code tags
This User Gave Thanks to migurus For This Post:
# 4  
Old 09-22-2011
thanks all!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to rename the repeating strings

All, I have a sample text like below. Key (Header) Key1 ABC Key2 ABC Key3 ABC ABC Key4 ABC Key5 ABC ABC ABC Required Output Key (Header) Key1 (2 Replies)
Discussion started by: ks_reddy
2 Replies

2. Shell Programming and Scripting

Deleting Repeating lines from a txt file via script

Hi, I'm having trouble in achieving the following scenario. There is a txt file with thousands of lines and few lines are repeated, which needs to be removed using a script. File.txt 20140522121432,0,12,ram Loc=India,,, 1 2 3 4 . . 30... (18 Replies)
Discussion started by: Gautham
18 Replies

3. Shell Programming and Scripting

Creating repeating record in between file through script

apprecieate your help to resove this. My source file looke like 1001 000 HEADER 1001 001 RAJESH 1001 002 100 1001 002 200 1001 002 500 1001 006 FOOTER 1002 000 HEADER 1002 001 RAMESH 1002 002 100 1002 002 200 1002 002 500 1002 006 FOOTER my... (8 Replies)
Discussion started by: Ganesh L
8 Replies

4. UNIX for Dummies Questions & Answers

Need help with repeating variables in a shell script

I should preface this by saying I have never worked with shell scripts before so this is all new to me. I was able to make something that worked, but is terribly optimized, and I have no idea how to improve it. If anything it's a pretty hilarious script: #/bin/bash get_char() { ... (4 Replies)
Discussion started by: ricco19
4 Replies

5. Shell Programming and Scripting

Shell script to extract data in repeating tags from xml

Hi, I am new to shell scripting. I need to extract data between repeating tags from an xml file and store the data in an array to process it further. <ns1:root xmlns:ns1=""> <ns1:interface>in1</ns1:interface> <ns1:operation attribute1="true" attribute2="abd"... (2 Replies)
Discussion started by: sailendra
2 Replies

6. 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= /usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp open $host bin cd ${directory} put $files quit ftp and the .netrc file contain machine login abc... (4 Replies)
Discussion started by: varu0612
4 Replies

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

8. UNIX for Advanced & Expert Users

unix script for repeating a command with a variable

Hi need urgent help , for creating unix script . To collect system name,This is command i want to execute n (integer) no. of times for for a differnt IP addresses .IP is variable in every execution. Other string & collecter name is constant . snmpGet %IP% sysName.0 -c <string> -S <datacollecter... (2 Replies)
Discussion started by: langdatyagi
2 Replies

9. Shell Programming and Scripting

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... (9 Replies)
Discussion started by: cstovall
9 Replies

10. Shell Programming and Scripting

Repeating commands in a script

I have written a script that I want to be repeated. The script that I wrote outputs the date, how many people are on the system, how many people logged in before me, and how many people logged in after me. Than what I want it to do is after it outputs the 4 lines I want it to go back to the... (4 Replies)
Discussion started by: Dave2874
4 Replies
Login or Register to Ask a Question