Operating System - HP-UX
1767188 Members
5972 Online
108959 Solutions
New Discussion

Re: fetch the last file in directory

 
NDO
Super Advisor

fetch the last file in directory

 

Hi

 

I have a scritp that ftp to a server to get a file, with following format HLRxx_mmddyyyy, where xx is 04 and mm is the month, dd= day and yyyy = year.

My script:

#!/usr/bin/sh

cd /moneta_polled01/download1

HOST=10.100.48.47
USER=hlr_dump
PASSWD=dump123

/usr/bin/ftp -nv $HOST <<EOF
user $USER $PASSWD

binary
mget *HLR*
bye
EOF

 as it is gets all HLR files, but I just want the last, 

 

Please can you give me a hint?

 

 

 

 

 

 

3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: fetch the last file in directory

>gets all HLR files, but I just want the last, 

 

To get the last file requires you to first do a ls to get the list of files, then you can do a get.

And hope nothing changes between the two ftp sessions.

NDO
Super Advisor

Re: fetch the last file in directory

Hi

 

But the source server is a windows system, so I can use a "dir" command but how to actually getting the last file

Dennis Handly
Acclaimed Contributor

Re: fetch the last file in directory

>the source server is a windows system, so I can use a "dir"

 

ls should work too.

 

>how to actually getting the last file

 

For Unix/Linux, you can use "ls -t" and the latest will be at the beginning, add -r for end.

If ftp on Windows actually invokes the DOS dir command, you can use: dir /od

The latest is at the end.

 

For Unix/Linux you can also put the output into a file.

Note: The options and file needs to be quoted so one parm.

ls "-t *HLR*" out-file