Shell script to ftp latest file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to ftp latest file
# 1  
Old 11-22-2007
Shell script to ftp latest file

Hello All,
Hope u r doing fine.
I'm writing a shell script to ftp the latest file having pericular convention as 'ULTI_15072007043205.txt' on daily basis.
Now the date & timing of the file geleration isnt constant, so the file name daily varies as per the date & timing of generation.
Can anyone advice me how I can tackle with this?

Shilpa
# 2  
Old 11-22-2007
You use could 'ls' to return you the names sorted by date.

Quote:
Originally Posted by NetBSD
-t Sort by time modified (most recently modified first) before sorting the operands by lexicographical order.
then use the first one.
# 3  
Old 11-22-2007
atomated ftp script, modify as per your request

#! /bin/sh
#Do an ftp and get the list of filenames starting with ULT
ftp -ivn hostname <<INPUT >& out
user rakesh Welcome
ls ULT*
bye
INPUT

#Obtain the latest filename inside the variable filename using sort command
filename=`awk '{if($NF ~ "ULT") {print $NF}}' out | sort -r | sed -ne '1p'`


#Do ftp again and get the desired file
ftp -ivn hostname <<INPUT >& out
user rakesh Welcome
get $filename
# 4  
Old 11-22-2007
the ls executed on ftp is different from our full fledged ls
# 5  
Old 11-22-2007
My suggestion reading your query ...

REQUIRED_FILETYPE=UTIL_
...
cd ${DESIRED_DIR}
FILE=`ls -t ${REQUIRED_FILETYPE}* | sed '1q'`
echo ${FILE}
...
Then perform your outbound FTP.


Hope that helps.

Cheers,
Cameron
# 6  
Old 11-22-2007
Thanks a lot to all, this really has helped a lot.....

Shilpa
# 7  
Old 11-23-2007
Hi Cameron,

FILE=`ls -t ${REQUIRED_FILETYPE}* | sed '1q'`

I tried this,, it would not work, because the ls executed on ftp is not the same as the actual ls as mention in the previous mail.

i wished it would work, so that the work become little easier

here is the output if run ls and pipe its output to sed

ftp> ls -t UT* | sed '1p'
usage: ls remote-directory local-file
ftp>

RUV
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

FTP script to get latest file from server

Hello people, I have to download, with a scheduled script, the latest file from an FTP server. In the remote DIR, named .../TEKNONET/60468/, every night a CDR file like this gets uploaded into it: 000006046820151122N001.CDR, so my script will have to download every day the previous day... (12 Replies)
Discussion started by: virtus96
12 Replies

2. Shell Programming and Scripting

Download latest file via ftp server unix through shell script

Hello this is my first post in this forum , I dont want to be unhappy.. I am writing one script but facing difficulty to find the latest file with some new pattern My requirement is 1. The file is coming like "ABCD-23220140303" at FTP server once in a week. 2. script will run on daily... (3 Replies)
Discussion started by: ajju
3 Replies

3. Shell Programming and Scripting

Help with korn shell script to get the latest file versions in a directory

I want to write a korn shell script to get the latest three versions for a file in the directory having lot of files with various versions (files with prefix as same but time stamp as suffix) and compress it and at the same time have to remove the remaining versions of the file (other than latest... (4 Replies)
Discussion started by: maheshbabu
4 Replies

4. Shell Programming and Scripting

Shell script to get the latest file from the file list and move

Hi, Anybody help me to write a Shell Script Get the latest file from the file list based on created and then move to the target directory. Tried with the following script: got error. A=$(ls -1dt $(find "cveit/local_ftp/reflash-parts" -type f -daystart -mtime -$dateoffset) | head... (2 Replies)
Discussion started by: saravan_an
2 Replies

5. Shell Programming and Scripting

Needed shell script to get the latest file based on date

hi i need the shell script to get the file with latest date. for example in my input folder i have files like file_20130212.txt file_20130211.txt now my output folder should have the file with latest date i.e..file_20120212.txt i want to get the latest file .. i.e is should take... (6 Replies)
Discussion started by: hemanthsaikumar
6 Replies

6. Shell Programming and Scripting

Script to upload latest file to other server via FTP

Hello, I have a script that finds the latest version of a file in a folder on my Minecraft server. I'm trying to come up with something that will then FTP that file over to my fileserver. Here's what I have that finds the newest file: find /home/mc/archive/sbhouse -type f -mtime +45 -exec... (7 Replies)
Discussion started by: nbsparks
7 Replies

7. Shell Programming and Scripting

How to FTP the latest file, based on date, from a remote server through a shell script?

How to FTP the latest file, based on date, from a remote server through a shell script? I have four files to be FTP'ed from remote server. They are of the following format. build1_runtime_mmddyyyy.txt build2_runtime_mmddyyyy.txt build3_runtime_mmddyyyy.txt buifile_count_mmddyyyy.txt ... (9 Replies)
Discussion started by: imran_affu
9 Replies

8. Shell Programming and Scripting

How to get latest file via FTP session

Hello , My requirement is as follows: I want to connect to a remote FTP server using FTP and then get the latest file from server location can u pls share code snippet for this ? Regards, Suresh (4 Replies)
Discussion started by: sureshg_sampat
4 Replies

9. UNIX for Dummies Questions & Answers

ftp command to get latest file

Hi, I would like an FTP command or series of commands to get only the latest file. Is that possible? Thanks in advance. (2 Replies)
Discussion started by: laiko
2 Replies

10. UNIX for Dummies Questions & Answers

Getting latest file from ftp

Hi, i have multile JAMA01.DAT.* files in my ftp. how can i get the latest file in from the ftp by executing the script :rolleyes:? Regards, Arun S (3 Replies)
Discussion started by: arunavlp
3 Replies
Login or Register to Ask a Question