while loop logic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting while loop logic
# 1  
Old 10-24-2011
Power while loop logic

Hi,
Here I am trying to query database and check a value, if the value not matches then I wants to re-query the database.Once the value matches, I want to email the reqidstatus_log.txt file. Database query produces a file reqidstatus_log.txt which contains result.

But the query not working as per my expectations. Need your help on this ....


OS: Solaris Sparc 10
Shell Type: ksh
###############
Code:
while grep -i "no rows selected" reqidstatus_log.txt
do
  sleep 30
  sqlplus -s apps/<PASSWORD> << ENDOFSQL
    define reqid=107019657;
    spool reqidstatus_log.txt
    select REQUEST_ID,PHASE_CODE,STATUS_CODE
    from fnd_conc_req_summary_v where request_id='1070196571' and phase_code='C';
ENDOFSQL
done
uuencode reqidstatus_log.txt reqidstatus_log.txt | mailx -s "reqidstatus_log.txt" xyz@abc.com



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


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

Last edited by vgersh99; 10-24-2011 at 10:21 AM.. Reason: code tags, please!
# 2  
Old 10-24-2011
Can you explain your issue? It is really not clear to me... ( I understand ""seems to work... but not always ..." )
# 3  
Old 10-24-2011
Wrench

Quote:
Originally Posted by vbe
Can you explain your issue? It is really not clear to me... ( I understand ""seems to work... but not always ..." )
I am trying achive the following:
In the database one request will be running. That request runs for long time.
So instead of keep on checking it manually whether request is completed or not, I want shell script to check the request status (say for example every 1 minute) and if the request is completed then shell script should email me the request status ( that is it should email me the file generated by query, in this case it should email me file .txt file mentioned in the shell script).

The issues are :
1) its unnecessary keep on printing output on Standard output following text until condition is met.
==========
no rows selected

1
==========
2) Even if the request is completed and its phase_code is "C" (C- for completion).
my mentioned shell script keep on print about give ( no rows select and 1) to screen.

So the logic I used in the shell script me may be incorrect and I have to use FOR loop instead of this .... You your help.



Thanks,
Raj
# 4  
Old 10-24-2011
I may sound silly, but if all you are interested in is knowing the SQL query has finished, why not let the query tell you?(If its being called in a script...)

About your code:
You test :
Code:
while grep -i "no rows selected" reqidstatus_log.txt

will always be true... (You read always the same file that has the condition when you start...
Since we dont know how it is generated (one line every minute?) or his content, it will be difficult to suggest something... but perhaps try to use tail command to read X last lines of file, which may help the condition to change (X one to ?? lines?)

Last edited by vbe; 10-24-2011 at 11:36 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell/Perl logic for loop

Hi, I have a requirement as follows. Have 3 files. Need to match up the data in each one of them and sum up the data by a field and display it. example given below. File 1 : Name, Emp id File 2 : Empid, Subject, File 3 : Subject, Score, Class Match Emp id in File 1 and File 2 and then... (7 Replies)
Discussion started by: preethgideon
7 Replies

2. UNIX for Dummies Questions & Answers

if then else logic with while loop problem

Hi Friends, I have to do write a shell file based on one flag.If that flag value is 'N' then process look in $DATA are and the normal process continue.If vaule is 'P' then it check for the files in different location $CONV and move those file in $DATA area and rest of the process... (2 Replies)
Discussion started by: Param0073
2 Replies

3. Shell Programming and Scripting

loop logic inside of an inline redirect?

i need to log the feedback from the ftp server as i'm performing some deletes. the only way i know of to do this is with the inline redirect << EOF ... but from there to the closing EOF, it's like i'm at the ftp command prompt, so I don't know how to have ksh script logic in there I have an... (3 Replies)
Discussion started by: tlavoie
3 Replies

4. Shell Programming and Scripting

for loop logic with multiple parameters

hi, unix wizards, i have a question about the logic of my inner for loop below. first, what i am trying to do is to write a script called create_account that automatically creates mysql accounts. the user can provide a user_name or a group_id as an argument (and the script can take multiple... (1 Reply)
Discussion started by: ankimo
1 Replies

5. Shell Programming and Scripting

While Loop Logic

I would need to with making while loop logic working in shell program when I am new into the shell programing 1) I would need to try to get the file from the remote side ----need to try 15 mins apart for 4 times and terminate the program if file is not available.... I would need to know how I... (4 Replies)
Discussion started by: sambakamba
4 Replies
Login or Register to Ask a Question