Unix Shell - help with scripting

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > October 2006 > help with scripting





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author help with scripting
extents

2006-10-22, 7:20 am

Hi
I have some files on /bak/data/a.dbf
b.dbf
x.dbf so on

I have a text file defining where these files should be copied to ie
/data/sid/01/a.dbf
/data/sid/02/b.dbf
/data/sid/01/x.dbf and so on

How do I write a shell script to check whether a.dbf exists on
/bak/data/a.dbf and if its there copy it from /bak/data/a.dbf to
/data/sid/01/a.dbf and so on...

thanks

Janis Papanagnou

2006-10-22, 1:16 pm

extents wrote:
> Hi
> I have some files on /bak/data/a.dbf
> b.dbf
> x.dbf so on
>
> I have a text file defining where these files should be copied to ie
> /data/sid/01/a.dbf
> /data/sid/02/b.dbf
> /data/sid/01/x.dbf and so on
>
> How do I write a shell script to check whether a.dbf exists on
> /bak/data/a.dbf and if its there copy it from /bak/data/a.dbf to
> /data/sid/01/a.dbf and so on...
>
> thanks
>


You need to read the files from the textfile one by one

while read -r pathname
do
: ...
done <textfile

then extract the filename from the pathname

filename=${pathname##*/}

then test existance

if [ -f "/bak/data/$filename" ]
then
: ...
fi

and finally a copy (overwrite) if it's existing

targetdir=${pathname#%/*}
cp "/bak/data/$filename" "$targetdir"


Janis
extents

2006-10-23, 1:18 am

Hi
Is there any chance you help a little with the code. Im really new to
shell scripting and cant get my head around this!!! thanks a lot.


On Oct 22, 10:44 pm, Janis Papanagnou <Janis_Papanag...@hotmail.com>
wrote:
> extents wrote:
>
>
>
>
> while read-r pathname
> do
> : ...
> done <textfile
>
> then extract the filename from the pathname
>
> filename=${pathname##*/}
>
> then test existance
>
> if [ -f "/bak/data/$filename" ]
> then
> : ...
> fi
>
> and finally a copy (overwrite) if it's existing
>
> targetdir=${pathname#%/*}
> cp "/bak/data/$filename" "$targetdir"
>
> Janis- Hide quoted text -- Show quoted text -


extents

2006-10-23, 1:18 am

and how do i read only the lines starting with / from the text file pl?


On Oct 23, 1:54 pm, "extents" <exte...@gmail.com> wrote:[vbcol=seagreen]
> Hi
> Is there any chance you help a little with the code. Im really new to
> shell scripting and cant get my head around this!!! thanks a lot.
>
> On Oct 22, 10:44 pm, Janis Papanagnou <Janis_Papanag...@hotmail.com>
> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>

Janis

2006-10-23, 1:16 pm

extents wrote:

[ Please don't top-post! ]

>
> Hi
> Is there any chance you help a little with the code. Im really new to
> shell scripting and cant get my head around this!!! thanks a lot.


The posted code is shell code.

Put the cp command block into the if block
and the resulting if block into the while block.

Janis
[vbcol=seagreen]
> On Oct 22, 10:44 pm, Janis Papanagnou <Janis_Papanag...@hotmail.com>
> wrote:

extents

2006-10-25, 1:32 am

Thanks for the help Janis. All working.

On Oct 24, 12:52 am, "Janis" <janis_papanag...@hotmail.com> wrote:[vbcol=seagreen]
> extents wrote:[ Please don't top-post! ]
>
>
>
>
> Put the cp command block into the if block
> and the resulting if block into the while block.
>
> Janis
>
>
>
>
>
>
>
>
>
>
>
>
>
>

Janis Papanagnou

2006-10-25, 1:27 pm

extents wrote:
> Thanks for the help Janis. All working.


Glad to hear.
[vbcol=seagreen]
> On Oct 24, 12:52 am, "Janis" <janis_papanag...@hotmail.com> wrote:
>

You may in addition want to read http://cfaj.freeshell.org/google/
Has some valuable contents that you should follow if posting here.

Thank's.

Janis
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com