for i in range ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting for i in range ksh
# 1  
Old 03-21-2011
for i in range ksh

Hi guys i have one handy script which is written in bash and it was using `seq ` , since we want to modified it to ksh script.

i have tried couple of tricks to work around
for i in $(x..y) like syntax it dont work .

below is the actual code can somebody help me on it

Code:
#!/bin/ksh
if [ $# != 4 ]
then
echo "Syntax  genawrs.sh dbid instanceId startsnapid endsnapid"
exit 1
fi
l_dbid=$1
l_instid=$2
l_start_snapid=$3
let l_end_snapid=$4-1
for i in "$(l_start_snapid..l_end_snapid)"     <=  not sure how to take out i out it 
do
let l_next_snapid=$i+1;
l_awr_log_file="/u01/app/awr/awrrpt_${2}_${i}_${l_next_snapid}.log"
sqlplus -s / as sysdba << EOC
set head off
set pages 0
set lines 132
set echo off
set feedback off
spool $l_awr_log_file
SELECT
output
FROM
TABLE
(dbms_workload_repository.awr_report_html
($l_dbid,$l_instid,$i,$l_next_snapid)
);
spool off
EOC
done

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 03-21-2011 at 04:03 PM.. Reason: code tags, please!
# 2  
Old 03-21-2011
replace your for loop with (assuming your snapid are incremented by 1) otherwise you must consider another way to build up the list of the snap you want to get.
Code:
i=l_start_snapid
while [ $i -lt ${l_end_snapid} ]
do
      let l_next_snapid=$i+1
      l_awr_log_file="/u01/app/awr/awrrpt_${2}_${i}_${l_next_snapid}.log"
      ...
      ...
      ...
      let i+=1
done


Last edited by ctsgnb; 03-21-2011 at 04:52 PM..
# 3  
Old 03-21-2011
Thanks a lot for prompt reply

I changed the code according it.

Code:
l_start_snapid=$3
let l_end_snapid=$4-1
i=l_start_snapid
while [ $i -lt l_end_snapid ]
do
let l_next_snapid=$i+1;
l_awr_log_file="/u01/app/awr/awrrpt_${2}_${i}_${l_next_snapid}.log"
sqlplus -s / as sysdba << EOC
set head off
set pages 0
set lines 132
set echo off
set feedback off
spool $l_awr_log_file
SELECT
output
FROM
TABLE
(dbms_workload_repository.awr_report_text
($l_dbid,$l_instid,$i,$l_next_snapid)
);
spool off
EOC
let i+1
done

=======================================
but got it below error. i is not getting export. ???

Code:
(2529181125,1,l_start_snapid,7)
              *
ERROR at line 6:
ORA-00904: "L_START_SNAPID": invalid identifier


Last edited by vgersh99; 03-21-2011 at 05:10 PM.. Reason: once AGAIN - please use code tags!
# 4  
Old 03-22-2011
It looks like you forgot the dollar sign before the name of the variable
Code:
${l_start_snapid}

Code:
while [ $i -lt ${l_end_snapid} ]


Last edited by ctsgnb; 03-22-2011 at 10:28 AM..
# 5  
Old 03-22-2011
If your ksh is actually ksh93 (Korn shell 93), you can do ranges using {start..finish} syntax.

For example:
Code:
#!/bin/ksh93

for i in {11..15}; do
   echo $i
done

produces
Code:
11
12
13
14
15

Bash and zsh use the same syntax.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

IP Range Assigning

Hi All, I'm a bit confused about assigning IP address from IP Ranges. I am using this scenario below to understand. Scenario Adatum.com an international IT solutions company, is launching 12 new branches in a new country where they currently have no existing branches. The sWin CIO has asked... (3 Replies)
Discussion started by: TryllZ
3 Replies

2. UNIX for Advanced & Expert Users

Help with ksh script to list, then cp files from a user input date range

Hi, I'm quite new to ksh scripting, can someone help me with this. Requirements: I need to create a script that list the files from a user input date range. e. g. format of file: *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00*... (1 Reply)
Discussion started by: chococrunch6
1 Replies

3. UNIX for Dummies Questions & Answers

Classify value to a range

Dear All, I need to classify my data into sets or ranges based on values in the second column of a file as - low medium and high. INPUT: file1.dat 1.tmp 1.03 2.tmp 0.38 3.tmp 3.23 4.tmp 1.34 I would like to classify all the numerical values into a range based on the followng... (3 Replies)
Discussion started by: chen.xiao.po
3 Replies

4. Shell Programming and Scripting

different behaviour for ksh and ksh -x

I'm getting different behaviour when executing below script in debug option. $ cat ss.ksh ff=$(pwd) echo " ff : $ff" $ ksh ss.ksh ff : /tmp $ ksh -x ss.ksh + + pwd ff= + echo ff : ff : I was getting this behaviour in my actuall script i'm able to reproduce this in simple script... (4 Replies)
Discussion started by: luckybalaji
4 Replies

5. UNIX for Dummies Questions & Answers

Difference Between executing llike ./myscript.ksh and . ./myscript.ksh

Hi , What is the diffence between executing the script like ./myscript.ksh . ./myscript.ksh I have found 2 difference but could not find the reason 1. If i export a variable in myscript.ksh and execute it like . ./myscript.ksh the i can access the other scripts that are present in... (5 Replies)
Discussion started by: max_hammer
5 Replies

6. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

7. Shell Programming and Scripting

range in if using awk

Hi All, I would like to assign the following values to each column in my file. if $i is between 1 and -1 (ie -1 < $i < 1) then print A; if $i is between -2 and -1 && 1 and 2 (ie. -2 < $i < -1 && 1 < $i < 2) then print B; if $i is between -3 and -2 && 2 and 3 (ie. -3 < $i < -2 && 2 < $i < 3)... (1 Reply)
Discussion started by: Fredrick
1 Replies

8. Shell Programming and Scripting

print range between two patterns if it contains a pattern within the range

I want to print between the range two patterns if a particular pattern is present in between the two patterns. I am new to Unix. Any help would be greatly appreciated. e.g. Pattern1 Bombay Calcutta Delhi Pattern2 Pattern1 Patna Madras Gwalior Delhi Pattern2 Pattern1... (2 Replies)
Discussion started by: joyan321
2 Replies

9. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

10. Shell Programming and Scripting

Subscipt out of range - Error (ksh)

Folks, I have peculiar kind of error. my script goes like cat inputfile> while read param do Array=$param y=`expr $y + 1` done When i run script passing very large input file. script abends in the middle of execution saying "ksh: script... (6 Replies)
Discussion started by: sharifhere
6 Replies
Login or Register to Ask a Question