Get the latest file from UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Get the latest file from UNIX
# 1  
Old 03-02-2011
Get the latest file from UNIX

Dear Friends,

Am very much new to UNIX and this is my first task in UNIX. Can you pls help me with the below problem:

i want to get the latest file from unix to mainframes. I did the following

Code:
remote ls -t $AMR/data01/extract/monthly/source/- 
AMR_D*""_REC_STAT.dat - 
> v1 
remote head -1 v1 > stat

But when I receive stat as
Code:
set receive mode char 
receive - 
"!dcp ""$stat"" - - 
2>/tmp/stat.stderr" - 
DD:O1STAT

I receive nothing.
But when I hardcode the file instead of $stat i was able to receive 535 bytes.
If I give only stat instead of $stat, I get the file with full path as output.
Am I missing something here?

Can you pls help?
Appreciate your response on this.

Regards
Amar

Moderator's Comments:
Mod Comment Please use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks.

Last edited by zaxxon; 03-02-2011 at 03:58 AM.. Reason: code tags
# 2  
Old 03-02-2011
Please tell us what type of mainframe OS you are using. Apart from those few Unix instructions, I can't see anything familiar.

Not sure if it helps you, but to list the latest file in a directory, you could issue
Code:
ls -t1| head -1

Since you issued the ls without the 1, you could have multiple files in that output, since it will not list 1 file per line.
# 3  
Old 03-02-2011
From your post I gather that you need to run stat on the most recent file in the directory which matches your pattern.

If I interpreted you correctly what you need to do is either use xargs, or substitute the value of the ls | head in the arg list of stat using backticks or command substitution.
eg.
Code:
stat `ls -t $AMR/data01/extract/monthly/source/-AMR_D*""_REC_STAT.dat | head -1`
OR
stat $(ls -t $AMR/data01/extract/monthly/source/-AMR_D*""_REC_STAT.dat | head -1)
OR
ls -t $AMR/data01/extract/monthly/source/-AMR_D*""_REC_STAT.dat | head -1| xargs stat

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need help with UNIX command to get the latest file from list of files with timestamp

Hi All, I have list of files like below with name abcxyz.timestamp. I need a unix command to pick the latest file from the list of below files. Here in this case the lates file is abcxyz.20190304103200. I have used this unix command "ls abcxyz*|tail -1" but i heard that it is not the appropriate... (2 Replies)
Discussion started by: rakeshp
2 Replies

2. Shell Programming and Scripting

UNIX command to get the latest file and also matching pattern

we want to fetch the latest file in a given directory and also the file name should match the below pattern Example file name ->hrdata-2015-10-13-16-45-26.xml(2015-10-13-16-45-26- it is not current timestamp, we just need to check for the pattern) We expect the file will have the... (3 Replies)
Discussion started by: vishwanath001
3 Replies

3. UNIX and Linux Applications

Need to copy the latest file from Unix server to Shared folder

Hi All, One job in unix server will generate .csv files daily. I need to copy the latest of these .csv file from the unix server to the shared drive/folder in windows through unix script. My shared folder will look something like W:\some folder(for example). Could any one of you please help... (3 Replies)
Discussion started by: jaya@123
3 Replies

4. Shell Programming and Scripting

How to find the latest file on Unix or Linux (recursive)

Hi all, I need to get the latest file. I have found this command "ls -lrt" that is great but not recursive. Can anyone help? Thanx by advance. (7 Replies)
Discussion started by: 1or2is3
7 Replies

5. Shell Programming and Scripting

SFTP latest file from Windows server to Unix host

Hi All, I am SFTP ing file from Windows server (Sydney) to Unix host in London (both servers are on different timezones). It appears the upstream (Windows server team) does not do a file housekeeping activity and henceforth there are multiple files i.e. each week the script is scheduled to run... (1 Reply)
Discussion started by: vigdmab
1 Replies

6. Shell Programming and Scripting

How to find the latest modified file from the unix server.

hi Friends, In my directory i have some files. I need to find out latest modified file. Please help me. Sreenu. (2 Replies)
Discussion started by: sreenu80
2 Replies

7. Shell Programming and Scripting

ftp the latest file from unix to windows

Hi, I have a ftp script to ftp files from unix to windows. Now i need to pull the latest file from unix to windows. It is not working. ftp -nvi $SERVER > ${FILE_DIR}/NavigationftpLog << EOD user $USER $PWD lcd $FILE_DIR echo "the local directory is $FILE_DIR" cd $Remote_PATH echo... (2 Replies)
Discussion started by: ammu
2 Replies

8. UNIX for Dummies Questions & Answers

How to find the latest file on Unix or Linux

Please help me out how to identify the latest file in one directory by looking at file's timestamp or datestamp. You can say using system command. Thanks (10 Replies)
Discussion started by: duke0001
10 Replies

9. AIX

Unix shell scripting to find latest file having timestamp embedded...

Hi guys, I have a directory in UNIX having files with the below format, i need to pickup the latest file having recent timestamp embedded on it, then need to rename it to a standard file name. Below is the file format: filename_yyyymmdd.csv, i need to pick the latest and move it with the... (2 Replies)
Discussion started by: kaushik25
2 Replies

10. UNIX for Dummies Questions & Answers

finding latest file in Unix

Hi, i want to search a file in the dir , if file exists for todays date print the message that file found or if file does not exist for todays date/ if file not found i want to display message saying that file not found. How to do this. Thx for your help. (2 Replies)
Discussion started by: nick12
2 Replies
Login or Register to Ask a Question