If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > ftp get file with timestamp

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-04-07, 16:48
maan_myra maan_myra is offline
Registered User
 
Join Date: Sep 2007
Posts: 7
Exclamation ftp get file with timestamp

Hi, my knowledge on UNIX scripting is very limited below is my script on getting my file on ftp site but there are bunch of csv files and I only want to get the latest posted on the site. Normally our vendor posted by namefile+date where look like this CML20070904 where
CML - name of the company
2007 - year
09 - month
04 - date

please help!


-----------------------------code --------------------------------
#!/bin/sh
# delelete old files
cd /u001/oracle/camstar/tins/csv_files
rm *.csv

HOST='ftp.site.com'
USER_ASE='ops1'
PASSWD_ASE='ash'

ftp -n $HOST << END_SCRIPT
quote USER $USER_ASE
quote PASS $PASSWD_ASE
mget *.csv
quit
END_SCRIPT
Reply With Quote
  #2 (permalink)  
Old 09-06-07, 09:13
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
It's difficult to test but would this do it ?
Do you want the files to keep the dates as part of the name?

Mike
Code:
#!/bin/sh

# delelete old files
cd /u001/oracle/camstar/tins/csv_files
rm *.csv

# variables
HOST='ftp.site.com'
USER_ASE='ops1'
PASSWD_ASE='ash'
TODAY=`date '+%Y%m%d'`

# ftp files
ftp -n $HOST << END_SCRIPT
   quote USER $USER_ASE
   quote PASS $PASSWD_ASE
   mget *$TODAY.csv
quit

exit 0
Reply With Quote
  #3 (permalink)  
Old 09-06-07, 13:52
maan_myra maan_myra is offline
Registered User
 
Join Date: Sep 2007
Posts: 7
Unhappy

Hi Mike,

Yes, I want to keept the timestamp together with my filename prefix 'CML'
I tried your scripts with 'TODAY' as variable but at first when i run it it display the correct format of the variable ex. (CML_20070906) but when it time to do the mget it gets all the file with this kind of format ex.(CML_20070906,CML_20070905,CML_20070904,CML_200 70903) how could i tell to my script only get what is posted today.

Myra

# variables
HOST='ftp.site.com'
USER_ASE='ops1'
PASSWD_ASE='ash'
TODAY=date '+CML_%Y%m%d'`

# ftp files
ftp -n $HOST << END_SCRIPT
quote USER $USER_ASE
quote PASS $PASSWD_ASE
mget *$TODAY.csv
quit

exit 0
Reply With Quote
  #4 (permalink)  
Old 09-07-07, 06:10
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Myra

Looking at you're code I think the line
TODAY=date '+CML_%Y%m%d'`
should read
TODAY=`date '+CML_%Y%m%d'`

so hopefully it's just a typo - sorry for replying late.

Mike
Reply With Quote
  #5 (permalink)  
Old 09-07-07, 14:06
maan_myra maan_myra is offline
Registered User
 
Join Date: Sep 2007
Posts: 7
Smile

Hi Mike,

Your syntax works! but when I assigned it on a variable and do my mget command it says "file not found".

What I did is to put it directly on my mget without using variable that look like this....

mget `date '+ASE_20%y%m%d.csv'`

thanks!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On