f



Ksh Scripting Help: question using 'find' and 'tar'

Hello,

I'm a newbie w/ ksh scripting. Here's my dilemma:

I have a directory w/ like 50 .bu files. Like file_1.bu, file_2.bu,
file_3.bu, etc. Approximately 10 new .bu files get written to this
directory everyday and the oldest 10 get removed everyday.

I'm trying to write a script that will identify the latest 10 being
written to that directory and tar them up.

So far if I use:

find /somedirectory -name "file_*" -mtime -10 -print > filename1.txt

this will give me all the .bu files, with full pathnames, that have
been modified in the last 10 days in a file called "filename1.txt".

Now that I have the .bu files identified in a file, how do I tar up all
10 of them? Maybe I'm just missing something easy.

Thanks!

0
dawaves (69)
7/21/2006 10:06:06 PM
comp.unix.aix 10963 articles. 1 followers. drkirkby (98) is leader. Post Follow

5 Replies
978 Views

Similar Articles

[PageSpeed] 58

tar -cf filename.tar $(cat /path/to/filename1.txt)

dawaves wrote:
> Hello,
>
> I'm a newbie w/ ksh scripting. Here's my dilemma:
>
> I have a directory w/ like 50 .bu files. Like file_1.bu, file_2.bu,
> file_3.bu, etc. Approximately 10 new .bu files get written to this
> directory everyday and the oldest 10 get removed everyday.
>
> I'm trying to write a script that will identify the latest 10 being
> written to that directory and tar them up.
>
> So far if I use:
>
> find /somedirectory -name "file_*" -mtime -10 -print > filename1.txt
>
> this will give me all the .bu files, with full pathnames, that have
> been modified in the last 10 days in a file called "filename1.txt".
>
> Now that I have the .bu files identified in a file, how do I tar up all
> 10 of them? Maybe I'm just missing something easy.
> 
> Thanks!

0
mirchr (40)
7/22/2006 12:58:24 AM
dawaves wrote:
> Hello,
> 
> I'm a newbie w/ ksh scripting. Here's my dilemma:
> 
> I have a directory w/ like 50 .bu files. Like file_1.bu, file_2.bu,
> file_3.bu, etc. Approximately 10 new .bu files get written to this
> directory everyday and the oldest 10 get removed everyday.
> 
> I'm trying to write a script that will identify the latest 10 being
> written to that directory and tar them up.
> 
> So far if I use:
> 
> find /somedirectory -name "file_*" -mtime -10 -print > filename1.txt
> 
> this will give me all the .bu files, with full pathnames, that have
> been modified in the last 10 days in a file called "filename1.txt".
> 
> Now that I have the .bu files identified in a file, how do I tar up all
> 10 of them? Maybe I'm just missing something easy.

Yes.

Make a history file which contains all of the .bu files

ls *.bu > CURRENT

Whenever you want the new ones,

mv CURRENT OLD

ls *.bu > CURRENT

diff CURRENT OLD

Most tar commands will accept a list in some manner.

"man tar"
0
nobody4 (271)
7/22/2006 2:18:59 AM
Best way to sort the latest 10 files  would be using ls

ls -lrt *.bu | tail -n 10 > filename1.txt


tar -cvf last10.tar -L filename1.txt
  will tar all the latest 10 files that has been extracted .


base60 wrote:
> dawaves wrote:
> > Hello,
> >
> > I'm a newbie w/ ksh scripting. Here's my dilemma:
> >
> > I have a directory w/ like 50 .bu files. Like file_1.bu, file_2.bu,
> > file_3.bu, etc. Approximately 10 new .bu files get written to this
> > directory everyday and the oldest 10 get removed everyday.
> >
> > I'm trying to write a script that will identify the latest 10 being
> > written to that directory and tar them up.
> >
> > So far if I use:
> >
> > find /somedirectory -name "file_*" -mtime -10 -print > filename1.txt
> >
> > this will give me all the .bu files, with full pathnames, that have
> > been modified in the last 10 days in a file called "filename1.txt".
> >
> > Now that I have the .bu files identified in a file, how do I tar up all
> > 10 of them? Maybe I'm just missing something easy.
>
> Yes.
>
> Make a history file which contains all of the .bu files
>
> ls *.bu > CURRENT
>
> Whenever you want the new ones,
>
> mv CURRENT OLD
>
> ls *.bu > CURRENT
>
> diff CURRENT OLD
> 
> Most tar commands will accept a list in some manner.
> 
> "man tar"

0
7/23/2006 6:47:44 AM
In article <1153637264.197870.163990@i42g2000cwa.googlegroups.com>, praveen <praveen.varrier@gmail.com> wrote:
> Best way to sort the latest 10 files  would be using ls
>
> ls -lrt *.bu | tail -n 10 > filename1.txt
>
> tar -cvf last10.tar -L filename1.txt
>   will tar all the latest 10 files that has been extracted .

Or, to make it one line, without intermediate files:

	# ls -lrt *.bu | tail -n 10 | xargs tar -cvf last10.tar

-Dan
0
usenet38 (424)
7/23/2006 6:52:11 AM
praveen wrote:
> Best way to sort the latest 10 files  would be using ls

Quite true, but if you read the OP it didn't say 10 -- he
said approximately 10

Since the number isn't static, what you propose below won't
suffice.

> 
> ls -lrt *.bu | tail -n 10 > filename1.txt
> 
> 
> tar -cvf last10.tar -L filename1.txt
>   will tar all the latest 10 files that has been extracted .
> 
> 
> base60 wrote:
>> dawaves wrote:
>>> Hello,
>>>
>>> I'm a newbie w/ ksh scripting. Here's my dilemma:
>>>
>>> I have a directory w/ like 50 .bu files. Like file_1.bu, file_2.bu,
>>> file_3.bu, etc. Approximately 10 new .bu files get written to this
>>> directory everyday and the oldest 10 get removed everyday.
>>>
>>> I'm trying to write a script that will identify the latest 10 being
>>> written to that directory and tar them up.
>>>
>>> So far if I use:
>>>
>>> find /somedirectory -name "file_*" -mtime -10 -print > filename1.txt
>>>
>>> this will give me all the .bu files, with full pathnames, that have
>>> been modified in the last 10 days in a file called "filename1.txt".
>>>
>>> Now that I have the .bu files identified in a file, how do I tar up all
>>> 10 of them? Maybe I'm just missing something easy.
>> Yes.
>>
>> Make a history file which contains all of the .bu files
>>
>> ls *.bu > CURRENT
>>
>> Whenever you want the new ones,
>>
>> mv CURRENT OLD
>>
>> ls *.bu > CURRENT
>>
>> diff CURRENT OLD
>>
>> Most tar commands will accept a list in some manner.
>>
>> "man tar"
> 
0
nobody4 (271)
7/23/2006 7:15:58 PM
Reply: