The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
get latest file inquirer Shell Programming and Scripting 4 04-02-2009 11:15 AM
Getting latest file from ftp arunavlp UNIX for Dummies Questions & Answers 3 02-08-2008 10:19 AM
script to find latest executable in particular directory and start that particular ex kvineeth Shell Programming and Scripting 6 09-24-2007 07:19 AM
Unix shell scripting to find latest file having timestamp embedded... kaushik25 AIX 2 08-06-2007 10:42 PM
Reading file names from a file and executing the relative file from shell script anushilrai Shell Programming and Scripting 4 03-10-2006 05:25 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-22-2007
im_new im_new is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 15
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 (permalink)  
Old 11-22-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
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 (permalink)  
Old 11-22-2007
uvrakesh uvrakesh is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 74
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 (permalink)  
Old 11-22-2007
uvrakesh uvrakesh is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 74
the ls executed on ftp is different from our full fledged ls
  #5 (permalink)  
Old 11-22-2007
Cameron's Avatar
Cameron Cameron is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Brisbane, Australia
Posts: 499
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 (permalink)  
Old 11-22-2007
im_new im_new is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 15
Thanks a lot to all, this really has helped a lot.....

Shilpa
  #7 (permalink)  
Old 11-23-2007
uvrakesh uvrakesh is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 74
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 01:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0