Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW TO FIND THE LATEST FILE BY FILES'S EXTENSION

Status
Not open for further replies.

vaanand

Programmer
Apr 5, 2001
2
US
I am a UNIX newbie so excue me for my simple question. I am using HP-UNIX. The problem is I want to log into a remote server and pick out one file whose file extesion is the latest date and FTP it back into my local server . And I also want to get the name of the file I picked so that I have to use this file name for some other purpose. The whole thing should be korn shell script so that I can automate these processes.For example in the remote server there could be 4 or 5 files with same name but with different date extension as zzz.20010405,zzz.200010404,zzz.20010403. I need pick out the highest dated file extension. My script should pick zzz.20010405 and FTP this file to my local server and I need to get this file name into variable for other processing.

2) problem 2 is after FTP ing the largest date extension file to my local server i need to move these file in the remote server to another archive directory in the same remote server from Home directory of the remote server.

Thanks in advance.
Andy
 

Hi, vaanand!

Please, try this command for the first problem:

ls -1 | awk '$1 > prev { prev = $1 } END { print prev }'

$1 in awk script can be $0. The highest dated file has name that is last in alphabetic order - awk script will pick up his name.

This command works if in directory are only zzz.* files.

Bye!

KP.
 
You can have other files in the directory also if the filename searching is the same you can do the following:
ls -1 zzz* | awk '$1 > prev { prev = $1 } END { print prev }'

As for #2, is your output in /home/user and you want it to be in say /home/user/temp?

You could use remsh if you have this access.
code:
remsh remoteserver -l username "command to run"

So say you have 2 unix boxes: unix1 and unix2. You also have accounts on both as User1.
You need to edit the .rhosts file on both boxes in your home directory to have the following:

unix1 .rhosts file:
unix2 User1

unix2 .rhosts file:
unix1 User1

##NOTE: you could do + + to allow all access.

Once this is done just do the following from unix1:
remsh unix2 -l User1 "mv /home/user/zzz.20010101 /home/user/temp/."

##NOTE: I didn't test this but should point you in a direction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top