Hi, i am getting error from below script.
Error: s1.sh: line 19: ((: j<: syntax error: operand expected (error token is "<")
#!/bin/bash
str=$(ps -eaf | grep smon | grep -v grep | awk ' {print $8}' | cut -c10-18)
i=1
while [ 1 ]
do
temp=`echo $str|awk '{print $"'$i'"}'`
if [ "$temp" = "" ]
then
break
fi
eval "var_$i"=$temp
i=`expr $i + 1`
done
for ((j=1;j<$i;j++))
do
export ORACLE_SID='$'var_$j
source $HOME/.bash_profile
$ORACLE_HOME/bin/sqlplus / as sysdba << EOF
spool '/u02/lak/s1.txt' append
select username from all_users;
spool off;
EOF
done
str=" TEST LAK"
Thanks
Lak.
what is value of $i ? it can be null ?
no, check it in While loop, first it is assigned to 1 and incremented in while loop according to input of str.
can you write to output
str=$(ps -eaf | grep smon | grep -v grep | awk ' {print $8}' | cut -c10-18)
you use to source .bash_profile (it goes ~/bashrc and also it goes /etc/bashrc )
your answer is below 
$ grep -H 'unset i' /etc/bashrc
/etc/bashrc: unset i
therefore your $i --> NULL and for loop fails
regards
ygemici
okey fine. what can i add to my code to successful execution of my script.
---------- Post updated at 03:23 PM ---------- Previous update was at 10:03 AM ----------
any one their to help me out of this problem.
Hi,
Just rename $i to $iamnoti for example.
It solved. But when I am storing var_$iamnoti its just storing as var_1,var2. not real values
for ((j=1;j<$i;j++)) do export ORACLE_SID='$'var_$j source $HOME/.bash_profile $ORACLE_HOME/bin/sqlplus / as sysdba << EOF spool '/u02/lak/s1.txt' append select username from all_users; spool off; EOF done
sorry,
#!/bin/bash
str=$(ps -eaf | grep smon | grep -v grep | awk ' {print $8}' | cut -c10-18)
inc=1
while [ 1 ]
do
temp=`echo $str|awk '{print $"'$inc'"}'`
if [ "$temp" = "" ]
then
break
fi
eval "var_$inc"=$temp
inc=`expr $inc + 1`
done
for ((j=1;j<$inc;j++))
do
ORACLE_SID='$'var_$j
export ORACLE_SID
echo $ORACLE_SID
source $HOME/.bash_profile
$ORACLE_HOME/bin/sqlplus / as sysdba << EOF
spool '/u02/lak/s1.txt' append
select username from all_users;
spool off;
EOF
done
Chirel
12
The closing is [/CODE] . . .
Try adding this
eval ORACLE_ID='$'var_$j
lots of thanks Chirel
. atlast, my script working fine without Errors. 