Another shellscript question

Folks;

on a unix server I have a mapping file which holds a list mountpoints of all databases and their mountpoints. tab delimited or colon deliminted..I needed to copy the datafiles from the pristine mountpoints to test's mountpoints in this case. I needed to do this by passing sid name using $SID. How can I perform that?

ex.
cat mapfile.lst
test /u01:/u02:/u03:/u04
dev /u05:/u06:/u07:/u08

Pristine mountpoints
/u01p:/u02p:/u03p:/u04p

thanks

I came up with this but its not working..I somehow need to do the following.
a. grep for test then move onto building the cp query. the cp query should look like..
cp -rp /u01_p /pristine u01/oradata/test
cp -rp /u02_p /pristine u02/oradata/test

for i in `cat dbmap|awk '{for (i=2; i<=NF; ++i) print $i}'`;
do
cp -p -r ${i} $i
done

  1. what's 'dbmap'?
  2. how's the '/u01_p' derived in your 'cp' sample?
  3. given sample file inputs [mapfile.lst and prestine.txt] , what the sample desired output?

Please try to explain the input and the desired output as clearly as you possibly can with the sample data.

  1. dbmap is the mapfile.lst file which holds the following data.
    test /u01:/u02:/u03:/u04
    dev /u05:/u06:/u07:/u08

  2. I dont now how to derive the '/u01_p' mountpoint. There are 8 mountpoints with that for source and target. the source is always static but the target is could be /u01..u08 or /u11..u18 or /u21..u28
    '/u01_p'
    '/u02_p'
    ...
    '/u08_p'

the cp example i gave "cp -rp /u01_p /pristine u01/oradata/test" is what i need to derive from the routine...
ex.. the desired output should be...

cp -rp /u01_p /pristine u01/oradata/test
cp -rp /u02_p /pristine u02/oradata/test
....................
cp -rp /u08_p /pristine u08/oradata/test

given your mapfile....

nawk -f jig.awk mapfile

with jig.awk containing:

{
  n=split($2, arr, ":")
  for(i=1; i <= n; i++)
    printf("cp -rp %s_p /pristine %s/oradata/%s\n", arr, arr, $1)
}

produces

cp -rp /u01_p /pristine /u01/oradata/test
cp -rp /u02_p /pristine /u02/oradata/test
cp -rp /u03_p /pristine /u03/oradata/test
cp -rp /u04_p /pristine /u04/oradata/test
cp -rp /u05_p /pristine /u05/oradata/dev
cp -rp /u06_p /pristine /u06/oradata/dev
cp -rp /u07_p /pristine /u07/oradata/dev
cp -rp /u08_p /pristine /u08/oradata/dev

Is that something that you're after?

definately. some questions. How are you catting the mapfile in the code?
the output you got was the following
code:
cp -rp /u01_p /pristine /u01/oradata/test
cp -rp /u02_p /pristine /u02/oradata/test
cp -rp /u03_p /pristine /u03/oradata/test
cp -rp /u04_p /pristine /u04/oradata/test
cp -rp /u05_p /pristine /u05/oradata/dev
cp -rp /u06_p /pristine /u06/oradata/dev
cp -rp /u07_p /pristine /u07/oradata/dev
cp -rp /u08_p /pristine /u08/oradata/dev
code:
but what if I just want to build a copy statement for test and omit dev? I somehome wanted to incorporate $SID value which should equal to test.

thanks

nawk -v sid="${SID}" -f jig.awk mapfile

sid == $1 {
  n=split($2, arr, ":")
  for(i=1; i <= n; i++)
    printf("cp -rp %s_p /pristine %s/oradata/%s\n", arr, arr, $1)
}

Thanks..i tried testing the code you gave me...but the output was different. What am I doing wrong? I am not good with awk/shell programming. the other thing is that the output should be like the following..

cp -rp /u09_p/pristine /u09/oradata/test
cp -rp /u10_p/pristine /u10/oradata/test <---/u10 is not being grabbed

not
cp -rp /u09_p/pristine /u09/oradata/test
cp -rp /u01_p/pristine /u01/oradata/dev

thanks again,

mapfile
test:/u09:/u10
dev:/u01:/u02

awk -v sid="${SID}" -f 3.sh dbmap2

cat 3.sh
sid == $1
{
n=split($2, arr, ":")
for(i=1; i <= n; i++)
printf("cp -rp %s_p /pristine %s/oradata/%s\n", arr[i], arr[i], $1)
}

this is NOT the mapfile sample you gave before.
WHICH one do you need?

sorry, I need it for the last 1 I posted?

thanks.

nawk -F: -v sid="${SID}" -f jig.awk mapfile

jig.awk:

sid == $1 {
  for(i=2; i <= n; i++)
    printf("cp -rp %s_p /pristine %s/oradata/%s\n", $i, $i, $1)
}

not getting anything back..
jbld@tabloo:/home/oracle/scripts/a> awk -F: -v sid="${SID}" -f jig.awk mapfile
jbld@tabloo:/home/oracle/scripts/a>
jbld@tabloo:/home/oracle/scripts/a> export SID=test
jbld@tabloo:/home/oracle/scripts/a> awk -F: -v sid="${SID}" -f jig.awk mapfile

jbld@tabloo:/home/oracle/scripts/a> cat mapfile
test:/u09:/u10
dev:/u01:/u02

jbld@tabloo:/home/oracle/scripts/a> cat jig.awk
sid == $1 {
for(i=2; i <= n; i++)
printf("cp -rp %s_p /pristine %s/oradata/%s\n", $i, $i, $1)
}

I'm sorry - I'm bad - use 'nawk' instead of 'awk':

sid == $1 {
  for(i=2; i <= NF; i++)
    printf("cp -rp %s_p /pristine %s/oradata/%s\n", $i, $i, $1)
}

We dont have nawk in HPUX unless I dont know the path.... We have awk though..pls help....

ok, try it with awk as is.

Question; how can Incorporate this whole thing in 1 script? assuming the mapfile is an external file.

you really need to start reading the man pages......

nawk -F: -v sid="${SID}" '
  sid == $1 {
    for(i=2; i <= NF; i++)
      printf("cp -rp %s_p /pristine %s/oradata/%s\n", $i, $i, $1)
  }' mapfile

1 last request pls..I promose to take some scripting classes..I am a dba by profession not a shellscripting expert like you guys are....

 
> cat newmaptest 

  this is source      this is destination 
/s01/oradata/jbld:/u01/oradata/test 
/s02/oradata/jbld:/u02/oradata/test 

how can i get the following command
cp -rp /s01/oradata/jbld /u01/oradata/test
cp -rp /s02/oradata/jbld /u02/oradata/test

thanks a lot

> cat newmaptest 
/s01/oradata/jbld:/u01/oradata/test 
/s02/oradata/jbld:/u02/oradata/test 
> sed -e 's/^/cp -rp /g;s/:/ /' newmaptest
cp -rp /s01/oradata/jbld /u01/oradata/test
cp -rp /s02/oradata/jbld /u02/oradata/test

Thanks Matrix Madhan and vgersh99. That really helped.

-Jigar