help in running while loop inside a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help in running while loop inside a shell script
# 8  
Old 11-16-2011
Quote:
Originally Posted by rishav
try this: (not tested)

I have executed the code :
Code:
#!/bin/ksh
db_user=$DB_USER_NAME
db_pwd=$DB_PASSWORD
db_sid=$TWO_TASK
if [ $# -ne 1 ]; then
echo "\tUsage: MoveUsageProcessing <BC Log file Name>"
exit 1
else
BCLogFileName=$1
fi
grep -i  'MoveUsage daemon needs to run on this account before it can be billed'  $1 |awk -F\| '{for(i=0;++i<=NF;) if($i ~ /Acct/) print substr($i,6)}' > ./$1.txt
echo " log file path is : './$1.txt' ";
sqlplus -s /nolog |&
print -p "connect $db_user/$db_pwd@$db_sid"
print -p "SPOOL output.txt"
while read var_ack_party_name
do
print -p "select ACK_PARTY_NAME,bus_event_seq_nbr from bus_event where ack_party_name like 'MOVE_USAGE_DAEMON%' and event_data_text like '%"$var_ack_party_name"' "
done


But it didnt worked..and also it is not coming out of loop...an empty file output.txt is created.
# 9  
Old 11-16-2011
You try to read from stdin instead of the file, use
Code:
while read var_ack_party_name
do
print -p "select ACK_PARTY_NAME,bus_event_seq_nbr from bus_event where ack_party_name like 'MOVE_USAGE_DAEMON%' and event_data_text like '%"$var_ack_party_name"' "
done <$1.txt


# 10  
Old 11-17-2011
Quote:
Originally Posted by hergp
You try to read from stdin instead of the file, use
Code:
while read var_ack_party_name
do
print -p "select ACK_PARTY_NAME,bus_event_seq_nbr from bus_event where ack_party_name like 'MOVE_USAGE_DAEMON%' and event_data_text like '%"$var_ack_party_name"' "
done <$1.txt


I have tried this but this also didnt gave me expected result:
Code:
#!/bin/ksh
db_user=$DB_USER_NAME
db_pwd=$DB_PASSWORD
db_sid=$TWO_TASK
if [ $# -ne 1 ]; then
echo "\tUsage: MoveUsageProcessing <BC Log file Name>"
exit 1
else
BCLogFileName=$1
fi
grep -i  'MoveUsage daemon needs to run on this account before it can be billed'  $1 |awk -F\| '{for(i=0;++i<=NF;) if($i ~ /Acct/) print substr($i,6)}' > ./$1.txt
echo " log file path is : './$1.txt' ";

sqlplus -s /nolog |&
print -p "connect $db_user/$db_pwd@$db_sid"
print -p "SPOOL output.txt"

while read var_ack_party_name
do
print -p "select ACK_PARTY_NAME,bus_event_seq_nbr from bus_event where ack_party_name like 'MOVE_USAGE_DAEMON%' and event_data_text like '%"$var_ack_party_name"' "
done <$1.txt


I ran this and the output is as below :newtrial.ksh 20111011.71BC.LOG

log file path is : './20111011.71BC.LOG.txt'

No file is created.
# 11  
Old 11-17-2011
I am not so familiar with sqlplus, but shouldn't every single SQL command end with a terminator like ';'?

Code:
...
sqlplus -s /nolog |&
print -p "connect $db_user/$db_pwd@$db_sid;"
print -p "SPOOL output.txt;"

while read var_ack_party_name
do
print -p "select ACK_PARTY_NAME,bus_event_seq_nbr from bus_event where ack_party_name like 'MOVE_USAGE_DAEMON%' and event_data_text like '%"$var_ack_party_name"'; "
done <$1.txt

This User Gave Thanks to hergp For This Post:
# 12  
Old 11-17-2011
Quote:
Originally Posted by hergp
I am not so familiar with sqlplus, but shouldn't every single SQL command end with a terminator like ';'?

Code:
...
sqlplus -s /nolog |&
print -p "connect $db_user/$db_pwd@$db_sid;"
print -p "SPOOL output.txt;"

while read var_ack_party_name
do
print -p "select ACK_PARTY_NAME,bus_event_seq_nbr from bus_event where ack_party_name like 'MOVE_USAGE_DAEMON%' and event_data_text like '%"$var_ack_party_name"'; "
done <$1.txt

It worked Thankyou:-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to write a Boolean variable which succeed and failed inside the if loop in shell script ?

I have if loop with multiple variable value check in if loop. How can i print only if loop satisfied variable and its value in shell script ? I dont want to check each variable in if loop. That makes my script larger. if ] then echo "Only satisfied variable with value" ... (3 Replies)
Discussion started by: prince1987
3 Replies

2. Shell Programming and Scripting

Running a script as root but with different users inside

Hi All, my script.sh has the below lines, and i need to run the script as root or wam. please tell me if this will work #!/bin/bash sudo -t wam /usr/local/wam/stopwam -r ------- this needs run as wam user /usr/local/web/stopweb -a --- this needs to run as... (18 Replies)
Discussion started by: nanz143
18 Replies

3. Shell Programming and Scripting

If else condition inside for loop of awk command in UNIX shell scripting

Hi , Please excuse me for opening a new thread i am unable to find out the syntax error in my if else condition inside for loop in awk command , my actual aim is to print formatted html td tag when if condition (True) having string as "failed", could anyone please advise what is the right... (2 Replies)
Discussion started by: karthikram
2 Replies

4. Shell Programming and Scripting

Running .sh file inside a shell script

Hello, You might help a newbie like me, I am trying to run a .sh inside my shell script. After running that I need to execute below commands. Here's how my scripts looks like. Hope you can help: #!/bin/sh cd $ORACLE_HOME/owb/bin/unix ./OMBPlus.sh ---> goes to OMB+> directory cd... (10 Replies)
Discussion started by: aderamos12
10 Replies

5. Shell Programming and Scripting

How to increment date using "for loop" in format MMDDYY inside the shell script?

Need to increment the date from "currentdate + 90days" inside the for loop (i=1 to i=50) (5 Replies)
Discussion started by: aroragaurav.84
5 Replies

6. Shell Programming and Scripting

How to give a variable output name in a shell script inside a for loop

Hi all I run my program prog.c in the following way : $ ./prog 1 > output.txt where 1 is a user defined initial value used by the program. But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files. Like $ ./prog 1... (1 Reply)
Discussion started by: alice06
1 Replies

7. Windows & DOS: Issues & Discussions

How to log current timestamp inside a for loop in windows shell?

below is the output where i'm getting the same times tamp throughout the loop., where i'm expecting that to log the current time stamp.. C:\Users\ilango>for /l %i in (1,1,5) do echo for %i C:\Users\ilango>echo for 1 for 1 C:\Users\ilango>echo for 2 for 2 C:\Users\ilango>echo... (1 Reply)
Discussion started by: ilan
1 Replies

8. Shell Programming and Scripting

Running a unix script(which is calling another script inside that) in background

Hi all, I am having a script ScriptA which is calling a script ScriptB in the same server and copying files to second server and have to execute one script ScriptC in the second server. THis First script ScriptA is the main script and i have to execute this process continously. for Keeping... (2 Replies)
Discussion started by: rohithji
2 Replies

9. Shell Programming and Scripting

C Shell - Command Inside a Loop

I have a command nested in some while loops to parse some data that looks something like this. while ($condition) while ($condition) ... gzcat /dir/$fileName.gz | grep $searchString > out_file end end On the first loop, the command is executed properly (and takes maybe 10... (3 Replies)
Discussion started by: hobbers
3 Replies

10. UNIX for Dummies Questions & Answers

running sed inside script file

i am substituting some text in the xml file using sed, on shell directly it works fine, but when i run it inside script file, it say, the function cant be parsed, i think the prob is due to xml file, kindly help (4 Replies)
Discussion started by: bajaj111
4 Replies
Login or Register to Ask a Question