get_multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting get_multiple files
# 1  
Old 01-28-2011
get_multiple files

I need the shell script to get the last 5 files from the recently modified files.

I know that i have to some how loop and get the result, but not sure!

Can someone help!
# 2  
Old 01-28-2011
Please state what Operating System and version you are running and what Shell you use.

Please expand your post substantially to include example directory listings (blotting anything confidential with X's) and a full description of the process and sample matching output.


Code:
Simple answer based on the information provided would be:

ls -latr | tail -5

Or.
ls -1tr | tail -5


Last edited by methyl; 01-28-2011 at 05:17 PM.. Reason: typos and idea for solution
# 3  
Old 01-28-2011
Thanks for the reply! Am using XP os, and the bash shell!

I have got a bunch of files which are ftp'd on a box. i can list them.. out of them, i need the names of the lastest 5 updated files[Sorting by time] Assuming 5 files gets posted for a day.

otherwise, i need the script which can give me the names of the files posted the day before.[Sorting by date]

---------- Post updated at 04:37 PM ---------- Previous update was at 04:29 PM ----------

Methyl,
Hope i can explain more clearly!!
i am on one particular server [say xyz] and i can use the command "ftp" to connect to remote server to see the files on a particular directory [abc] on that server.

Now my script on my sever [xyz] should give me the files uploaded to the directory on the remote server on that particular directory [abc] the day before, assuming we are running the script today!
# 4  
Old 01-28-2011
Now that we know that there is more than one server involved here and that "ftp" is involved, please post the exact Operating System and version of both servers and the product and version of ftp on both servers.

If Microsoft software is involved we will need Server O/S and ftp software versions to the last decimal place.

Please note that "ftp" is not Shell. Any commands I posted earlier are not necessarily relevant to "ftp" (it all depends on what environment we have here).

Please post what relevant commands you have tried (including any error messages) or other useful information.

Big question. Do you have "root" or perhaps "Administrator" access to both of the remote server and the local server? Can you make changes on both servers?


Please do post detailed examples describing input , processing and expected output.
# 5  
Old 01-28-2011
both the servers have microsoft XP os i have IPv6 , but i dont know about product version of ftp on the remote server.

I have used the following script
Code:
#!/bin/sh
SERVER=example.com
DIR=some_directory
FILE="$(echo ls -t | sftp -b- $SERVER:$DIR | head -n2 | tail -n1)"
echo get "$FILE" | sftp -b- $SERVER:$DIR

and am getting an error. file not found.

yes,, and i have all access on both servers!

Last edited by Franklin52; 02-01-2011 at 08:56 AM.. Reason: Please use code tags
# 6  
Old 01-28-2011
Quote:
#!/bin/sh
SERVER=example.com
DIR=some_directory
FILE="$(echo ls -t | sftp -b- $SERVER:$DIR | head -n2 | tail -n1)"
echo get "$FILE" | sftp -b- $SERVER:$DIR
The script syntax does not make a lot of sense to me though I think that I know what you are trying to do.
Please post the output from:
Code:
#!/bin/sh
SERVER=example.com
DIR=some_directory
FILE="$(echo ls -t | sftp -b- $SERVER:$DIR | head -n2 | tail -n1)"
echo "${FILE}"

I suspect that this output will contain either error messages, nothing, or MSDOS directory listing detail. My guess is error messages.

Ps. It is extraordinarily difficult to get a files list in updated date order from a Microsoft ftp server. The secret is to change the environment variable DIRCMD for the account concerned (see help "dir"). This is an old MSDOS trick which still works for Windows.
# 7  
Old 01-31-2011
Hi, My error message is "file not found".

" The secret is to change the environment variable DIRCMD for the account concerned (see help "dir"). This is an old MSDOS trick which still works for Windows. " Am sorry, i didnt understand this!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automate splitting of files , scp files as each split completes and combine files on target server

i use the split command to split a one terabyte backup file into 10 chunks of 100 GB each. The files are split one after the other. While the files is being split, I will like to scp the files one after the other as soon as the previous one completes, from server A to Server B. Then on server B ,... (2 Replies)
Discussion started by: malaika
2 Replies

2. Shell Programming and Scripting

Shell script for field wise record count for different Files .csv files

Hi, Very good wishes to all! Please help to provide the shell script for generating the record counts in filed wise from the .csv file My question: Source file: Field1 Field2 Field3 abc 12f sLm 1234 hjd 12d Hyd 34 Chn My target file should generate the .csv file with the... (14 Replies)
Discussion started by: Kirands
14 Replies

3. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 Replies

4. Shell Programming and Scripting

How to create zip/gz/tar files for if the files are older than particular days in UNIX or Linux?

I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also? I found one command which is to create gz file for the... (4 Replies)
Discussion started by: Mallikgm
4 Replies

5. Shell Programming and Scripting

need a shell script to extract the files from source file and check whether those files existonserve

Hi, I am new to shell scripting.Please help me on this.I am using solaris 10 OS and shell i am using is # echo $0 -sh My requirement is i have source file say makefile.I need to extract files with extensions (.c |.cxx |.h |.hxx |.sc) from the makefile.after doing so i need to check whether... (13 Replies)
Discussion started by: muraliinfy04
13 Replies

6. Shell Programming and Scripting

sort the files based on timestamp and execute sorted files in order

Hi I have a requirement like below I need to sort the files based on the timestamp in the file name and run them in sorted order and then archive all the files which are one day old to temp directory My files looks like this PGABOLTXML1D_201108121235.xml... (1 Reply)
Discussion started by: saidutta123
1 Replies

7. UNIX for Dummies Questions & Answers

write a program in c in unix that display the files(includ sub-direc and files within) in a sorted

the sorting is based on name of file, file size modification time stamps o f file it should dislay the output in the following format "." and ".." enteries should be ignored please give some idea how to do it (1 Reply)
Discussion started by: pappu kumar jha
1 Replies

8. Shell Programming and Scripting

How to extract data from indexed files (ISAM files) maintained in an unix server.

Hi, Could someone please assist on a quick way of How to extract data from indexed files (ISAM files) maintained in an UNIX(AIX) server.The file data needs to be extracted in flat text file or CSV or excel format . Usually we have programs in microfocus COBOL to extract data, but would like... (2 Replies)
Discussion started by: devina
2 Replies

9. Shell Programming and Scripting

How to retrieve all the linked script files/ctl files/sql files?

Hi I am going to migrate our datawarehouse system from HP Tru 64 Unix to the Red Hat Linux. Inside the box, it is running around 40 cron jobs; inside each cron job, it is calling other shell script files, and the shell script files may again call other shell script files or ctl files(for... (1 Reply)
Discussion started by: franksubramania
1 Replies
Login or Register to Ask a Question