Need script to compress the file for yesterday.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need script to compress the file for yesterday.
# 1  
Old 02-20-2012
Need script to compress the file for yesterday.

Hi,

I want to write script for the last 5 files to compress.
Code:
#!/bin/sh
a= ls -ltr | awk '{print $9}' | head -5  | tail -3
echo `compress $a`
exit 0

but this was telling "not found"

please modify the script if i am wrong.

Last edited by jim mcnamara; 02-20-2012 at 08:34 AM.. Reason: cose tags
# 2  
Old 02-20-2012
If you want the 5 most recent files use no head value just:
Code:
ls -ltr | awk '{print $9}' | tail -5 |

I am changing your code to see the files, you change it get the ones you want:
Code:
#!/bin/sh
ls -ltr | awk '{print $9}' | head -5  | tail -3 |
while read a
do
  compress $a
done
exit 0

# 3  
Old 02-20-2012
Some modification on your sample code snippet ,
Please let us know if it serves your purpose .

Code:
#!/bin/sh
a=`ls -ltr | awk '{print $9}' | head -5  | tail -3 | tr '\n' ' '`
compress $a
exit 0

# 4  
Old 02-20-2012
This would be safer with "ls -1" (one) rather than "ls -l" (ell) because it will deal with filenames containing space characters.
For example (remove the "echo" if this does do the correct files):

Code:
#!/bin/sh
ls -1tr | head -5  | tail -3 | while read a
do
         echo compress "$a"
done
exit 0

Quote:
I want to write script for the last 5 files to compress.
We do not understand your meaning of the word "last". Do you mean "newest" or "oldest" ?
# 5  
Old 02-20-2012
new files
# 6  
Old 02-20-2012
I've just realised that the "tail -3" is a (wrong?) attempt to avoid the "total" line from ls -lt (ell).
Don't need the "tail" if we used "ls -1t" (one).

Code:
#!/bin/sh
ls -1tr | head -5  |while read a
do
         # Remove echo if it finds the right files
         echo compress "$a"
done
exit 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to zip the files of yesterday

Hi I've the following requirement, where i need to zip the yesterday files every day . Yesterday's Files touch AB_XYZA_20130930183017.log touch AB_DY_XYZA_20130930183017.log touch AB_GZU_20130930183017.log touch AB_XYZA_20130930180023.log touch AB_DY_XYZA_20130930180023.log touch... (1 Reply)
Discussion started by: smile689
1 Replies

2. Shell Programming and Scripting

Getting yesterday's date in shell script

Im in EST, and im using the command CurrentDate=`TZ="EST+24" date +'%y%m%d'` to get the yesterday's date. Does this work perfectly for the boundary conditions of month end or year end(leap year) etc ? (2 Replies)
Discussion started by: prasperl
2 Replies

3. Shell Programming and Scripting

Script to Grep column 3 from csv file generated yesterday

Hello, Can any one please assist how to scirpt it: Every day a new log file is create and I want to process only the one generated yesterday and get the data of column 3 and 6. For example today's date is 24 then I want to get the data of log file created on 23rd. Log Files in... (7 Replies)
Discussion started by: sureshcisco
7 Replies

4. Shell Programming and Scripting

Script for checking yesterday's log

Hi, Have to check log file for yesterday, I have tried this script, but it is showing error as -d illegal option. res=max_total`date -d'yesterday'+%y%m%d`.log res=max_total`date +%y%m%d`.log this is working fine for today. Please help me on this. Thanks in advance, Neha. (3 Replies)
Discussion started by: NehaKrish
3 Replies

5. UNIX for Dummies Questions & Answers

Issue: Compress in unix server and FTP to windows and open the compress file using Winzip

Hi All ! We have to compress a big data file in unix server and transfer it to windows and uncompress it using winzip in windows. I have used the utility ZIP like the below. zip -e <newfilename> df2_test_extract.dat but when I compress files greater than 4 gb using zip utility, it... (4 Replies)
Discussion started by: sakthifire
4 Replies

6. Shell Programming and Scripting

Problem to get yesterday's date flatfile with shell script

hi, i was required to write a shell script to get yesterday's date flatfile. but i only know how to get today's date flatfile. Please observed my below scripting: Please help! Thanks ================================================= #!/bin/sh HOST='192.168.1.200' USER='ftp1'... (19 Replies)
Discussion started by: lifeseries
19 Replies

7. Shell Programming and Scripting

Yesterday date script

Hello All, I am using the below script to get yesterday date, but it is giving date of day before yesterday. Right now its 080906 but this code is giving 080904. And my requirement is 080905. #!/bin/sh CurrentDate=`TZ="GMT+24" date +'%y%m%d'` echo $CurrentDate; WHY? Please help.. ... (7 Replies)
Discussion started by: wakhan
7 Replies

8. Shell Programming and Scripting

unix script to takes the old data from a TXT file and compress them into new file

Hi, I am looking for the unix script which can takes the 2 month old data from a TXT file (there is one txt file in whiche messages are appended on daily basis) and compress them into new file.Please halp me out. (2 Replies)
Discussion started by: vpandey
2 Replies

9. UNIX for Dummies Questions & Answers

list file which is accessed yesterday

how can I use 'ls' to list file which is accessed yesterday? Thx :confused: (2 Replies)
Discussion started by: aaron_fong
2 Replies

10. UNIX for Dummies Questions & Answers

compress script

Hi, How wud I script a particular log file to be compressed at a particular time and to be uncompressed after say 2 hours ? Im on a aix 3.2 box . file to be compressed --- > # pwd # /zssps/sps06/slogfile Thanks (3 Replies)
Discussion started by: cubicle^dweller
3 Replies
Login or Register to Ask a Question