Latest file through SFTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Latest file through SFTP
# 22  
Old 03-30-2010
Hi,
I have changed the script as
#
echo "cd /home/data/" > getFilelist
echo "ls -l "ABC*" >> getFilelist
echo "quit" >> getFilelist

sftp -b getFilelist user@hostname >filelist <<EOF
#

which is now giving the output as
sftp> cd /home/data
sftp> ls -l ABC*
-rw-r--r-- 0 13106 7745 0 Mar 29 07:34 ABC29073411
-rw-r--r-- 0 13106 7745 0 Mar 29 07:34 ABC29073412
-rw-r--r-- 0 13106 7745 0 Mar 29 07:34 ABC29073413
-rw-r--r-- 0 13106 7745 0 Mar 29 07:34 ABC29073415
sftp> exit

To get ris of first 2 and last line, I tried using all the below script but not a single record is getting copied to new file.
I tried executing the below scripts on unix prompt and they are working file but these script are not working inside the shell script.

#
1) /usr/bin/sed 's/sftp//g' filelist > filelist1
2) sed '1,2d' filelist > filelist1 and sed '$d' filelist >> filelist1
3) sed '/sftp/d' filelist > filelist1
4) grep -v 'sftp' filelist > filelist1
#

The filelist1 file does not contain any record.

please advise.

---------- Post updated at 05:09 PM ---------- Previous update was at 03:39 PM ----------

I think I found the issue.
The first sftp command is closing the complete script due to which the rest of the script is not executing.
I have created another script just to connect the host server and calling the new script from first script.

Hope this will work.

---------- Post updated at 05:36 PM ---------- Previous update was at 05:09 PM ----------

Done. Smilie

Finally I am able to create the script which will fetch all the latest files from remote server.

Thanks you very much all for your support and inputs.
# 23  
Old 03-31-2010
So what does your full script look like?
# 24  
Old 04-07-2010
Latest files through sftp

Hi,

Sorry for late reply,

Please find the complete script

Code:
*********************
# To copy latest files which were created in the last 15 min 
# from upstream System Server to local Server
 
## changing the directory 
cd /home/data/
 
## Removing all the the existing Files received from Upstream System
rm -rf ABC*
 
## Creating Empty 'list_of_new_files_to_get' File
echo '' > list_of_new_files_to_get
 
## Removing the confirmation File.
rm -rf ABC_READY.txt
 
## Creating batch to get the files from upstream System
echo "cd /data/cmv/GMM" > getFilelist
echo "ls -l ABC*" >> getFilelist
echo "quit" >> getFilelist
 
## Calling other shell script to get all the  file list
    getCompleteFileList.sh
 
## Removing String 'Sftp' from the filelist 
sed '/sftp/d' filelist > filelist1

## comparing the new list with existing available list.
while read a b c d e f g h file
do
  grep $file Files_Receievd_ABC.txt>/dev/null
  if [ $? != 0 ] ; then
    echo get /data/cmv/GMM/$file >> list_of_new_files_to_get
  fi
done < filelist1
echo quit >> list_of_new_files_to_get

## Adding newly received files to the existing list 
cat list_of_new_files_to_get >> Files_Receievd_ABC.txt

## Removing string 'quit' from the complete list and copying the data to Temp file.

sed '/quit/d' Files_Receievd_ABC.txt > Files_Receievd_ABC_TEMP.txt
 
## renaming the temp file to existing File.
mv Files_Receievd_ABC_TEMP.txt Files_Receievd_ABC.txt
 
## get all the new files from upstream System
sftp -b list_of_new_files_to_get username@hostname

## creating confirmation File.
touch ABC_READY.txt

**************************
Code of getCompleteFileList.sh

#!/bin/ksh
# To get the file list from upstrea Server
# The scrip will be called from ABC_Sync.sh script

sftp -b /home/data/getFilelist userName@hostname >/home/data/filelist <<EOF
************************


Thank you all for your inputs.Smilie

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