Another shellscript question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Another shellscript question
# 1  
Old 11-17-2005
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

Last edited by jigarlakhani; 11-17-2005 at 05:44 PM..
# 2  
Old 11-22-2005
Quote:
Originally Posted by jigarlakhani
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.
# 3  
Old 11-28-2005
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
# 4  
Old 11-28-2005
Quote:
Originally Posted by jigarlakhani
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:
Code:
{
  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)
}

produces
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

Is that something that you're after?
# 5  
Old 11-28-2005
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
# 6  
Old 11-28-2005
Quote:
Originally Posted by jigarlakhani
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
Code:
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)
}

# 7  
Old 11-29-2005
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)
}
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk in shellscript

Dear Members, I have the following situation I do not understand: I have a large json encoded file which I need to grep and afterwards want to extract specific information. I use this command to to that: cat /tmp/file | awk -F '"fields":' '{print $2}' | awk -F '"description":' '{print $4}'... (6 Replies)
Discussion started by: crumble
6 Replies

2. Shell Programming and Scripting

Help with shellscript

I am new in shell script i want to convert .txt file in the format axsjdijdjjdk to a x s j d i j d j j d k (5 Replies)
Discussion started by: sreejithalokkan
5 Replies

3. Post Here to Contact Site Administrators and Moderators

help with backup shellscript

can any one advice on this.. create archive backup -yyyymmdd.tr.gzin the directory "backup" that includes the following directory " product/dev","product/uat"and product/maintain", yymmdd, stand for current date This archive needs to be perpared at 9PM every day Thanks advance (1 Reply)
Discussion started by: ksakil
1 Replies

4. UNIX for Dummies Questions & Answers

How can I do aliasing in shellscript?

#Example.sh alias rmv 'sh Example2.sh' when i execute exapme.sh alias name not working. how i solve this problem?? (9 Replies)
Discussion started by: arun508.gatike
9 Replies

5. AIX

ShellScript displays un necessary question marks

Hi, This is suman. I am very new to Shell Scripting. I have a shell script, when I run that script, it is displaying un necessary question marks. But in the scritpt, there is no any " echo ? " statement. Can anybody please help me what could be the cause for displaying question marks ?? ... (3 Replies)
Discussion started by: clnsharma123
3 Replies

6. Shell Programming and Scripting

Need help with shellscript

Hello. I am a novince at writing shell scripts but here is the question. I have to write a shell script that does the following: Once executed via crontab, the script should do the following: a. get date/time stamp in for format 10-MAR-05 and b. execute shell script my_script.sh (which... (2 Replies)
Discussion started by: jigarlakhani
2 Replies

7. UNIX for Advanced & Expert Users

shellscript problem

hI, Pls consider the following shell script #!/bin/csh -f sqlplus tkyte/tkyte <<"EOF" > tmp.csh set serveroutput on declare a number:=5; begin dbms_output.put_line( 'a:='||a ); end; / spool off "EOF" The above script does the followin 1)it connects... (1 Reply)
Discussion started by: ravi raj kumar
1 Replies

8. UNIX for Advanced & Expert Users

ftp in Shellscript

Can I do something like this from a shellscript ?: ftp 12.34.56.78 <<! username password put a.c bye ! It does not go through as the login fails. Is there any alternative to do the above requirement? Thanks in advance. Gowrish (3 Replies)
Discussion started by: ggowrish
3 Replies
Login or Register to Ask a Question