Latest file through SFTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Latest file through SFTP
# 1  
Old 03-25-2010
Latest file through SFTP

Hi,

I want to download the latest file published on remote server using SFTP connection.
The job will run at every 15 min hence should download only the latest file. The fileName will be like ABC_DDHHMISS.txt (DD- day, HH-hour, MI - Min, SS-Sec).
So there will be files with same date for previous month, hence while downloading I should avoid old files and extract only latest files.

I tried to use the below script where the TIMESTAMP_FILE will get touched as soon as the script completes so next time when the script will run, it will fetch all new files after the timestamp of TIMESTAMP_FILE.
but when i execute the below script it's unable to find the $TIMESTAMP_FILE as it's available in local server.

Please help me to fix the issue.

Code:
NEW_FILES=`ssh username@hostname find /data/feeds/OUT -type f 
-newer $TIMESTAMP_FILE -name "ABC*"`


Thanks in advance.
# 2  
Old 03-25-2010
Why not rename the files on the server or move them to a backup directory.
# 3  
Old 03-25-2010
Quote:
Originally Posted by jyoung
Why not rename the files on the server or move them to a backup directory.
Maybe he doesn't have write access to the remote server. Otherwise he could write the time stamp file on the remote server.
# 4  
Old 03-25-2010
Right, We do not have permission to write/move the files of remote server.
# 5  
Old 03-25-2010
Do it in two steps. First get a listing of the files on the remote server. Then examine the list and create a list of files to retrieve.
# 6  
Old 03-25-2010
Try something like this:
Code:
NEW_FILES="ssh username@hostname find /data/feeds/OUT -type f 
-newer `date -d "-15 minutes"` -name "ABC*"

with the command in back ticks.
That will check for files newer than the date - 15 minutes.

This only works with GNU date though. If they are running linux it should be gnu date


EDIT: doesn't look like you can specify a date for -newer :/ I think the 2 step process is going to be your best bet.

Last edited by markdjones82; 03-25-2010 at 02:35 PM..
# 7  
Old 03-26-2010
Can it work this way -
when the script executes first time, it will fetch all the files published for respecitve date. once received to local drive, when the script executes for next interval, we can read the last file received at first run, and send the same filename as a timestamp file to check on remote server and can retrive the rest of the files published after it.

Also, when I exeute the complete script, it dosen't do anything. It just run and didnot fetch any records.

when I execute only, ssh username@hostname I am getting below message -

'Last login: Fri Mar 26 04:24:37 2010 from ny1gmcollatp1.u
Access to this computer is prohibited unless authorised
Accessing programs or data unrelated to your job is prohibited
If you are not authorised, disconnect now.'

but when i use sftp username@hostname, I am able to connect without any issues.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Retrieve the Latest file in a folder using SFTP

HI Guys, Can anyone help me to retrieve the latest file from below example using SFTP I have below list of files in a folder v403t.lstprgms.sortin1 val027.d099.fwest.oct2711 xcelrptd.d1400sqp.dec1713.t040459.@02del xcelrptd.d1400sqp.dec1713.t073308.@02del... (3 Replies)
Discussion started by: heye18
3 Replies

2. Shell Programming and Scripting

Picking the latest file based on a timestamp for a Dynamic file name

Hi , I did the initial search but could not find what I was expecting for. 15606Always_9999999997_20160418.xml 15606Always_9999999998_20160418.xml 15606Always_9999999999_20160418.xml 9819Always_99999999900_20160418.xml 9819Always_99999999911_20160418.xmlAbove is the list of files I... (4 Replies)
Discussion started by: chillblue
4 Replies

3. Shell Programming and Scripting

Need to automate sftp and always get the latest file

hi guys the script is working but i need to change the file that i want to get to the latest.. i will use this as cron so i can get the latest sftp file evryday. pls help.. set user "big_user" set IP "XX.XX.XX" set dir "/export/home/oracle/REF/INPUT" spawn sftp $user@$IP expect sftp> ... (7 Replies)
Discussion started by: JONATHAN0919
7 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. UNIX for Dummies Questions & Answers

Find the latest file on remote sftp

Hi All, I need your help in finding the latest files in remote sftp and get those files to local server and process them. Please let me know I appreciate your valuable inputs. Thanks raj (7 Replies)
Discussion started by: rajeevm
7 Replies

6. Shell Programming and Scripting

Need to copy latest file using SFTP

Hi All, In my unix server, I have the following files: h1.txt h2.txt h3.txt and through SFTP i need to copy only the latest file to another unix server. Can you please let me know what command i need to use. Thanks in Advance, (2 Replies)
Discussion started by: HemaV
2 Replies

7. Shell Programming and Scripting

SFTP latest file from Windows server to Unix host

Hi All, I am SFTP ing file from Windows server (Sydney) to Unix host in London (both servers are on different timezones). It appears the upstream (Windows server team) does not do a file housekeeping activity and henceforth there are multiple files i.e. each week the script is scheduled to run... (1 Reply)
Discussion started by: vigdmab
1 Replies

8. Shell Programming and Scripting

get latest file

i have the following in my directory x: 3 files with the word "LIST" inside the files 2 files without the word "LIST" 1 folder (sudirectory) i want to get the filename of the latest file (timestamp) with the word "LIST". by the way the script and the list of files are in seperate... (4 Replies)
Discussion started by: inquirer
4 Replies

9. Shell Programming and Scripting

how to get the latest file

I am trying to scp the latest file which ends with "_abc.log". Can some help me figure out how can do that? (3 Replies)
Discussion started by: shehzad_m
3 Replies

10. Shell Programming and Scripting

How do I get the name of latest file?

1) How do I get the name of latest file in a variable? 2) Is it safe to delete all files from a dir I am doing cd $dir_name if return_code > 0 rm * fi what are other alternates to delete all files from a dir in a shell script? :) (5 Replies)
Discussion started by: Hangman2
5 Replies
Login or Register to Ask a Question