Tux

...making Linux just a little more fun!

Talkback:133/cherian.html

[ In reference to "Easy Shell Scripting" in LG#133 ]

Mudassar Khan [mudassar at jumpgames.co.in]


Tue, 6 Nov 2007 18:07:42 +0530

Hello, I am new one for shell programming. I want to write a shell script that.. 1) Read text file from source folder and past it in to a destination folder

2) Delete previous text file from destination folder (destination folder contain only one text file at a time)

3) And this moving of file happened on weekly basis (after completion of a week new text file copied in destination folder in weekly basis)

4) Which file will be copied in the destination folder is decided by week. If it is 1st week then p1.txt, if week 5th then p5.txt will be copied in destination folder.

5) Week will be start from any date decided by us (like 14 December on Fridays to 22 December Friday is 1st week and other weeks will be calculated by 14 December ). Please help me.

Regards, Mudassar Khan


Top    Back


Thomas Adam [thomas.adam22 at gmail.com]


Tue, 6 Nov 2007 12:52:06 +0000

On 06/11/2007, Mudassar Khan <mudassar@jumpgames.co.in> wrote:

> I am new one for shell programming.

And sending email, by the looks of it. Plain text only please. Don't send HTML email.

> 1)       Read text file from source folder and past it in to a destination
> folder
>
> 2)       Delete previous  text file from destination folder(destination
> folder contain only one text file at a time)

These are the same thing to me: see the mv(1) command.

> 3)       And this moving of file happened on weekly basis (after completion
> of a week new text file copied in destination folder in weekly basis  )

See cron, especially the @weekly directive for older dixie cron stuff, although most modern distros have /etc/cron.d/weekly/ and such for your use. You just drop a shell script in there, with the appropriate permissions.

> 4)       Which file will be copied in the destination folder is decided by
> week . If it is 1st week then  p1.txt  , if week 5th then p5.txt will be
> copied in destination folder.
>
> 5)       Week will be start from any date decided by us (like 14 December on
>  Fridays to 22 December Friday is 1st week  and other weeks will be
> calculated by 14 December ).

You would use date(1) for this.

Yes I am being vague, but this sounds like homework to me. :)

-- Thomas Adam


Top    Back