cancel
Showing results for 
Search instead for 
Did you mean: 

FTP Files using sysdate

SOLVED
Go to solution
Linux 10g RAC on HP box
Occasional Contributor

FTP Files using sysdate

Hi ALL
Is it possible to ftp only those files which is 1 day old i mean sysdate -1. Is there any script.
6 REPLIES
Viktor Balogh
Honored Contributor

Re: FTP Files using sysdate

are you looking for the files created or modified in the last day?

if the latter, there is the -mtime option of find to accomplish this:

# find -type f -mtime 1 -print

look at the man page of find for more info
****
Unix operates with beer.
Linux 10g RAC on HP box
Occasional Contributor

Re: FTP Files using sysdate

Hi thanx for the quick reply. I am talking about the files created.
klb
Valued Contributor

Re: FTP Files using sysdate


AFAIK there really is no way of scripting an FTP xfer that needs to know the date of the remote file, unless the name of the file contains the date.

I'm assuming you want to go to some remote box via ftp and get files that were created yesterday.

You could maybe go there and get an ls -Rl listing, bring that back to your local host, parse it and get a list of files you want, then go back out to the remote site and get the file.

??

-klb
Michael Steele_2
Honored Contributor

Re: FTP Files using sysdate

No. The ftp command set if very limited and not a command interpreter, or shell. So you accomplish this be moving files in and out of directories. You have an INPUT directory for files just delivered by ftp, and a cron job to go and look for them once a day. You have an OUTPUT directory and a cron job that calls ftp once a day to send out these files.

Note that these files are exclusively used to ftp source and destination, and you don't do any other work in them. For exmaple,

/home/ftpuser/INPUT/
/home/ftpuser/OUTPUT/

Everything that you are now asking to do, like :

find /opt/application/work/files

is performed in your own shell script that is called by cron.
Support Fatherhood - Stop Family Law
RC Park
Frequent Advisor
Solution

Re: FTP Files using sysdate

The answers given are all good, but allow me to summarize:

1. Your question leaves out details, so we must make numerous assumptions in order to answer.

Assumption 1: All files are already in a single directory on the source system

Assumption 2: You're referring to an entire 24 hour period from the execution of the script, not just files exactly 24 hours old, but any file created WITHIN the last 24 hours

Assumption 3: You're still growing as an admin and understanding the UNIX command set and the limitations of commands like ftp, and that's OK! That's why we enjoy this forum!

If the above assumptions are correct, then as an example, if you have 10 files in a single directory, 2 of which have been created in the last 24 hours, the following command might work without a script, but you might want to script this to provide error control and other things that the CLI cannot do on it's own:

[/home/parkrc/tmp]# ls -lrt
-rw-r--r-- 1 parkrc sys 203553 Mar 7 17:00 ntlock.new
drwxr-xr-x 4 parkrc sys 8192 Mar 16 11:25 Bonnie
-rw-r--r-- 1 root sys 61571 Mar 21 11:08 ts99
-rwxr-xr-x 1 root sys 462533 Apr 27 09:30 escsi_diag.out.gz
-rw-r--r-- 1 root sys 55676 Apr 27 09:30 fcddiag.out.gz
-rwxr-xr-x 1 root sys 466733 Apr 27 09:30 fclpdiag.out.gz
-rw-r--r-- 1 root sys 12686 Apr 27 09:30 syslog.log.gz
-rw-r--r-- 1 root sys 815 Apr 27 09:30 LMVinfo.out.gz
-rw-r--r-- 1 root sys 0 May 6 07:00 test1
-rw-r--r-- 1 root sys 0 May 6 11:04 test2

[/home/parkrc/tmp]# find . -mtime -1 -print |awk -F "/" '{print $2}' |grep [0-z]
test1
test2

(that verifies we're picking up the correct 2 files)

From here, whether using ftp OR sftp, you'll have these filenames ready to either put in a file list (>/tmp/flist) for use in your script. Various methods are available to setup a loop to pass each name to the "put" sub/ftp command. This is the stuff good admins are made of, so it's a great opportunity to stretch your wings here and learn some shell coding!


Dennis Handly
Acclaimed Contributor

Re: FTP Files using sysdate

Are you pushing or pulling the files?
If using put, you can simply use find(1) to collect a list and then script them in ftp as mentioned by Viktor.

If using get, you'll need to do a "ls" first and then parse the output, then feed it back into ftp as mentioned by klb.

>I am talking about the files created.

On Unix type systems, files don't have the creation date, only modification.