- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- to ftp a file with same time stamp.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 01:43 AM
09-20-2006 01:43 AM
NOTE: need only recent file of particular file type. file type will be the first 3 letters.
Solved! Go to Solution.
- Tags:
- ftp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 01:54 AM
09-20-2006 01:54 AM
Re: to ftp a file with same time stamp.
If you are using FTP to transfer files, then as you have seen, the files will be created on the receiving server with a current timestamp. If you want to replicate the timestamp of the file as it exists on the source server, I suggest that you perform an 'ls' of the file on the source server (with FTP); capture the timestamp information into a log file; and use the captured information to 'touch' your transferred file changing its 'mtime' accordingly.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 01:54 AM
09-20-2006 01:54 AM
Re: to ftp a file with same time stamp.
Or you will relinquish control to the receiving side. Receptor then will issue modtime command before receiving the file and upon completing of transfer, it will touch the file with the desired timestamp.
Neither of these methods are easy but doable.
Hope this helps.
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 02:04 AM
09-20-2006 02:04 AM
Solutionand welcome to your first ITRC question.
Can you please confirm that you want to transfer only the last file of a certain filetype from serverA onto serrverB.
So on ServerA:
AAAfile1
AAAfile2
BBBfile1
BBBfile2
BBBfile3
where the first three letters would indicate the filetype and the files are created in cronological order file1, file2,file3.
You would only want to ftp AAAfile2 and BBBfile3,as they are the last created?
Quickest way would be to rsh to ServerB, do a ls -rt AAA* | tail -1, which gives you AAAfile2. Then rcp that file.
Repeat for ls -rt BBB* | tail -1.
Otherwise you are probably stuck with the ftp "newer" command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 03:05 PM
09-20-2006 03:05 PM
Re: to ftp a file with same time stamp.
thnks for ur suggestion. But the problem being we dont know how many file types are present on that server!!!and i have to embed this ftp script in my shell script. So tail pipe(|)commands are not working and rsh is not working :( ...
and James thanks for ur nice idea.How can i redirect in an ftp session the output of ls command into a log?? and after redirecting, how can i match if there are so many files.?
thnks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 06:37 PM
09-20-2006 06:37 PM
Re: to ftp a file with same time stamp.
As to the keeping the last one, you may want to use sort -r u -k1.1,1.3 (the key is only the first 3 chars)
- Tags:
- tar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 07:06 PM
09-20-2006 07:06 PM
Re: to ftp a file with same time stamp.
Just have a look at my ftp script embedded in my unix script and plz let me know how and where to use tar/untar commands.
ftp -niv <<-EOF |tee -a $FTPLOG
open $SERVER
user $USER $PASSWORD
cd $FIRST_DIR
mget *.txt
mdelete *.txt
bye
Ican do any scripting related to my server..i cantdo anything at source side.
Thanks in advacne
- Tags:
- here doc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 07:35 PM
09-20-2006 07:35 PM
Re: to ftp a file with same time stamp.
So it looks like only the sort trick can be used to get the "last" files. You should copy the files to a temp directory, use the script to get the latest, move to the real directory, then remove the temp dir.
cd tmp-dir
mv $(ls | sort -r u -k1.1,1.3) real-dir/
This like Peter's suggestion but uses vector methods to get all at once.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 08:46 PM
09-20-2006 08:46 PM
Re: to ftp a file with same time stamp.
we cant use mv,sort commmands in ftp script. And if i use that after i get all the files, that will b of no use as the time stamp will be same for all the files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 09:15 PM
09-20-2006 09:15 PM
Re: to ftp a file with same time stamp.
My assumption was as Peter said, the time was encoded into the name of the file. If not, you will have to script on the source side or use ls to capture the time.
>How can I redirect in an ftp session the output of ls command into a log?? and after redirecting, how can I match if there are so many files?
Ah, looking at the man page:
ls [remote-directory] [local-file]
mdir remote-files local-file
(read carefully about the prompting issue)
ls "-tog ." same4
output to local-file: same4? y
Once you have the sorted time in same4, you can then figure out which is last.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 09:47 PM
09-20-2006 09:47 PM
Re: to ftp a file with same time stamp.
can you please supply an actual example of some of the filetypes.
You only want to retrieve the latest generated file of each filetype from server A, correct ?
Do you want to retain the creation date/time of the file as on ServerA onto ServerB ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 09:58 PM
09-20-2006 09:58 PM
Re: to ftp a file with same time stamp.
As dennis adviced, i have kept the files in a log file. But my problem now is im notknowing how to take the latesst file from that.
total 16
-rw-r----- 1 122 Sep 7 10:45 BUS01.PN000001.txt
-rw-r----- 1 129 Aug 18 09:52 VEC01.PN170899.txt
-rw-r----- 1 210 Aug 18 05:43 VEC01.PN170698.txt
-rw-r----- 1 154 Aug 18 05:43 VEC01.PN170598.txt
-rw-r----- 1 100 Aug 18 05:43 VEC01.PN170498.txt
-rw-r----- 1 210 Aug 18 05:35 VEC01.PN170699.txt
-rw-r----- 1 154 Aug 18 05:35 VEC01.PN170599.txt
-rw-r----- 1 100 Aug 18 05:35 VEC01.PN170499.txt
-rw-r----- 1 103 Sep 21 10:55 BUS01.PN000002.txt
This is the log and i want latest file of BUS and VEC type.this is just a sample there will be so many such types. Plz help me how to get this from the log??
Peter pls go thru this sample files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 10:19 PM
09-20-2006 10:19 PM
Re: to ftp a file with same time stamp.
If it was in time order, then you could do:
$ sort -u -k7.1,7.3 filelist
-rw-r-- 1 103 Sep 21 10:55 BUS01.PN000002.txt
-rw---- 1 100 Aug 18 05:35 VEC01.PN170499.txt
(The only possible problem with sort -u, it doesn't say which one it takes. This could be solved by using nl to number each line, then sort without -u with the two keys, then use awk to compare sequential lines and pick the biggest if the same partial key.)
Note you can't tell the difference between files modified in the same 60 second interval. But that should be handled by ls -t.
Piping this to awk '{print $7}' would give you the latest filenames.
- Tags:
- stable sort
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 10:28 PM
09-20-2006 10:28 PM
Re: to ftp a file with same time stamp.
total 16
-rw-r----- 1 103 Sep 21 10:55 BUS01.PN000002.txt
-rw-r----- 1 122 Sep 7 10:45 BUS01.PN000001.txt
-rw-r----- 1 129 Aug 18 09:52 VEC01.PN170899.txt
-rw-r----- 1 210 Aug 18 05:43 VEC01.PN170698.txt
-rw-r----- 1 154 Aug 18 05:43 VEC01.PN170598.txt
-rw-r----- 1 100 Aug 18 05:43 VEC01.PN170498.txt
-rw-r----- 1 210 Aug 18 05:35 VEC01.PN170699.txt
-rw-r----- 1 154 Aug 18 05:35 VEC01.PN170599.txt
-rw-r----- 1 100 Aug 18 05:35 VEC01.PN170499.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 10:59 PM
09-20-2006 10:59 PM
Re: to ftp a file with same time stamp.
- Tags:
- missing attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 11:13 PM
09-20-2006 11:13 PM
Re: to ftp a file with same time stamp.
I can hardly see the script in the attachment. There are so many ASCII symbols(jargons) in the txt file.Can you please paste ur script in the box itself???
and will your script give me the recent file of each file type???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 11:14 PM
09-20-2006 11:14 PM
Re: to ftp a file with same time stamp.
attached my version of a possible solution.
Once you have the answer you need, can you please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#28
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 11:14 PM
09-20-2006 11:14 PM
Re: to ftp a file with same time stamp.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 11:30 PM
09-20-2006 11:30 PM
Re: to ftp a file with same time stamp.
It's going to look the same but may have poor indentation.
>will your script give me the recent file of each file type???
Naturally. ;-)
Peter seems to have the ftp communication down, (but not taking advantage of (ls [remote-directory] [local-file])
I have just the sorting/selection here.
#!/usr/bin/ksh
# sorts filelist (-tog ouput) based on initial time order. If duplicates
# in first 3 bytes, pick first.
# -rw-r----- 1 103 Sep 21 10:55 BUS01.PN000002.txt
# Since can't trust sort -u -k, add line numbers.
FILE=filelist
nl -nrz $FILE | sort -k8.1,8.3 -k1n,1n | awk '
BEGIN { # prime for first line
getline
LAST=substr($8, 1, 3) # partial key
print $8 # filename
}
{
KEY=substr($8, 1, 3)
if (KEY != LAST) { # if new type
print $8 # filename
LAST=KEY # save key
}
next
} '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2006 12:44 AM
09-21-2006 12:44 AM
Re: to ftp a file with same time stamp.
thanks for your help. please let me keep this post open for 3 more days till i get some confirmations DENNIS i specially thank u for ur patience and great help.
Thnku very much PETER...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2006 01:05 AM
09-21-2006 01:05 AM
Re: to ftp a file with same time stamp.
may i know what does the option -k1n,1n in sort command do????
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2006 07:37 AM
09-21-2006 07:37 AM
Re: to ftp a file with same time stamp.
It declares a numeric key with the position of the first field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2006 03:29 AM
09-28-2006 03:29 AM
Re: to ftp a file with same time stamp.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2006 07:46 AM
09-28-2006 07:46 AM