Need logic for shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need logic for shell scripting
# 1  
Old 10-29-2010
MySQL Need logic for shell scripting

I am comfortable with shell scripting. I need a better logic for below,

I've a reference file, to take the parameter value. For example in the no of channel is 6 i have get the commands as written below. I need need a differenct logic to extract the commands.

Code:
NO_OF_CHANNEL=6
 
 
case ${NO_OF_CHANNEL} in 
      1) RMANCH1="allocate channel disk1 type disk;" 
         RMANCH2="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANCH3="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANCH4="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANCH5="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANCH6="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANRL1="release channel disk1;" 
         RMANRL2="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANRL3="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANRL4="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANRL5="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANRL6="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
      ;; 
      2) RMANCH1="allocate channel disk1 type disk;" 
         RMANCH2="allocate channel disk2 type disk;" 
         RMANCH3="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANCH4="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANCH5="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANCH6="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANRL1="release channel disk1;" 
         RMANRL2="release channel disk2;" 
         RMANRL3="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANRL4="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANRL5="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANRL6="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
      ;; 
      3) RMANCH1="allocate channel disk1 type disk;" 
         RMANCH2="allocate channel disk2 type disk;" 
         RMANCH3="allocate channel disk3 type disk;" 
         RMANCH4="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANCH5="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANCH6="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANRL1="release channel disk1;" 
         RMANRL2="release channel disk2;" 
         RMANRL3="release channel disk3;" 
         RMANRL4="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANRL5="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
         RMANRL6="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';" 
      ;; 
. 
. 
. 
. 
. 

. 
. 
. 
. 
. 
. 
esac

###############################################

Can anyone give me different logic for this. Cz the No of channels have increased to 24 now and its difficult to right 24 cases as given above.

If anyone dont understand the question please heads up. I ll explain in detail. Kindly help me in any new logic.

Thanks in advance...

Gopalan

Last edited by pludi; 10-29-2010 at 08:25 AM..
# 2  
Old 10-29-2010
MySQL Need logic for shell scripting

U can try for loop Smilie?
like this
Code:
#!/bin/sh
TOTAL_NO_OF_CHANNEL=24
#NO_OF_CHANNEL your input
for((i=0;i<TOTAL_NO_OF_CHANNEL;i++))
do
  if [ $i -le $NO_OF_CHANNEL ]
  then
    RMANCH$i="allocate channel disk$i type disk;"
    RMANRL$i="release channel disk$i;"
  else
    RMANCH$i="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';"
    RMANRL$i="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';"
  fi
done


Last edited by Kesavan; 10-29-2010 at 08:27 AM..
# 3  
Old 10-29-2010
You need to use eval for this. For example:
Code:
NO_OF_CHANNEL=6
default="sql 'alter session set nls_date_format=\"DD-MON-YY HH24:MI:SS\"';"
for i in 1 2 3 4 5 6; do
  if [ $i -le $NO_OF_CHANNEL ]; 
    eval "RMANCH$i=\"allocate channel disk$i type disk;\""
    eval "RMANRL$i=\"release channel disk$i;\""
  else
    eval "RMANCH$i=\"\$default\""
    eval "RMANRL$i=\"\$default\""
  fi
done

# 4  
Old 10-29-2010
By the way ... a better solution in my opinion is to set the nls_date_format in the environment of the user executing the RMAN command (.profile .dbenv or other...depending on which is used when logging on).

Last edited by ctsgnb; 10-29-2010 at 09:09 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX shell scripting logic

This is my source file and required output is mentioned as below. Any input on how to proceed. start name=vamsi phone=123456789 mailid=abc@gmail.com adress:-india end start name=vamsi1 phone=1234567890 mailid=abc1@gmail.com adress:-usa end required output:... (15 Replies)
Discussion started by: vamsi.valiveti
15 Replies

2. Shell Programming and Scripting

Shell script logic

Hi I have a requirement where I have to generate a mail/alert to the user if any QA check is failed. our oracle jobs run in unix environment and log file is created . Sample is given below . SELECT * FROM product.fact_tally WHERE period_id = '20130401' ; LIMIT 5; Ideally the above... (4 Replies)
Discussion started by: systemee
4 Replies

3. Shell Programming and Scripting

Shell or PERL Logic

Hello All, Currently i am working on a logic in PERL scripting ... But i am sort of stuck up, can any one please help. Here goes. 1. Search for a pattern in a file 2. If the pattern matched lets say 10 lines 2.1 Reterive the first line and check for another pattern 2.1.1 if... (1 Reply)
Discussion started by: maxmave
1 Replies

4. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

5. Shell Programming and Scripting

Parent/Child Scripting logic Question

I have Parent script that will execute a child script. The child script will take about 2 hours to run and I wanted to somehow build a logic for parent.sh to wait and perform ps -ef|grep cp|grep -v on the child.sh cp process and loop and check return code of child.sh $? as well. Once they are both... (3 Replies)
Discussion started by: jigarlakhani
3 Replies
Login or Register to Ask a Question