LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 10-19-2011, 08:55 AM   #1
rajsp217
LQ Newbie
 
Registered: Jun 2011
Posts: 12

Rep: Reputation: Disabled
Cool while loop


Hi,
OS: Solaris Sparc 10.
===================
VARIABLE=grep "no rows selected" file_name
while (VARIABLE='desired_value')
do
repeat this test
else
email file_name
===================
In the above scenario, how can I take value in to VARIABLE and how while loop can be implemented to above mentioned requirement.

you need suggestions.

Thanks,
Raj

Last edited by rajsp217; 10-19-2011 at 08:58 AM.
 
Old 10-19-2011, 09:58 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Assuming you're using KornShell,
Code:
#!/bin/ksh
#       let's just use a for...
for file in $(grep -l "no rows selected" path_to_files)
do
        print "no rows selected from ${file}" | mailx -s "No Rows in ${file}" who@where.what
done
Hope this helps some.
 
1 members found this post helpful.
Old 10-20-2011, 04:39 AM   #3
rajsp217
LQ Newbie
 
Registered: Jun 2011
Posts: 12

Original Poster
Rep: Reputation: Disabled
Cool

Quote:
Originally Posted by tronayne View Post
Assuming you're using KornShell,
Code:
#!/bin/ksh
#       let's just use a for...
for file in $(grep -l "no rows selected" path_to_files)
do
        print "no rows selected from ${file}" | mailx -s "No Rows in ${file}" who@where.what
done
Hope this helps some.
############

When I run given below script, its giving syntex error. any idea why ?

========================================================================================

echo "Script To check request id status"

sqlplus -s apps/<password> << ENDOFSQL
define reqid=$REQID;
spool reqidstatus_log.txt
select REQUEST_ID,PHASE_CODE,STATUS_CODE
from fnd_conc_req_summary_v where request_id='106994181' and phase_code='C';
ENDOFSQL

for reqidstatus_log.txt in (grep -l "no rows selected" reqidstatus_log.txt)
do
print "no rows selected from reqidstatus_log.txt" | mailx -s "No Rows in ${file}" who@where.what
done
echo "emailing spoolfiles"
uuencode reqidstatus_log.txt reqidstatus_log.txt | mailx -s "reqidstatus_log.txt" who@where.what
echo "Finished request id status check"
exit
========================================================================================


following is the execution log:

Script To check request id status
DEFINE requires a value following equal sign

no rows selected

reqidstat.sh: syntax error at line 10: `$' unexpected
 
Old 10-20-2011, 05:40 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Which is your (default) shell? Here is a /bin/tcsh script:
Code:
#!/bin/tcsh
sqlplus -s apps/<password> << ENDOFSQL
  define reqid=$REQID;
  spool reqidstatus_log.txt
  select REQUEST_ID,PHASE_CODE,STATUS_CODE
  from fnd_conc_req_summary_v where request_id='106994181' and phase_code='C';
ENDOFSQL

while ( `grep "no rows selected" reqidstatus_log.txt` != "" )
  sleep 30
  sqlplus -s apps/<password> << ENDOFSQL
    define reqid=$REQID;
    spool reqidstatus_log.txt
    select REQUEST_ID,PHASE_CODE,STATUS_CODE
    from fnd_conc_req_summary_v where request_id='106994181' and phase_code='C';
ENDOFSQL
end

# 
#  The sqlplus command is succesfully terminated: send mail notification now!
#
<mail command here>
 
Old 10-20-2011, 06:08 AM   #5
rajsp217
LQ Newbie
 
Registered: Jun 2011
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
Which is your (default) shell? Here is a /bin/tcsh script:
Code:
#!/bin/tcsh
sqlplus -s apps/<password> << ENDOFSQL
  define reqid=$REQID;
  spool reqidstatus_log.txt
  select REQUEST_ID,PHASE_CODE,STATUS_CODE
  from fnd_conc_req_summary_v where request_id='106994181' and phase_code='C';
ENDOFSQL

while ( `grep "no rows selected" reqidstatus_log.txt` != "" )
  sleep 30
  sqlplus -s apps/<password> << ENDOFSQL
    define reqid=$REQID;
    spool reqidstatus_log.txt
    select REQUEST_ID,PHASE_CODE,STATUS_CODE
    from fnd_conc_req_summary_v where request_id='106994181' and phase_code='C';
ENDOFSQL
end

# 
#  The sqlplus command is succesfully terminated: send mail notification now!
#
<mail command here>

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



Default sheel is "ksh"


Thx,
Raju
 
Old 10-20-2011, 06:26 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
ksh version is almost the same (differences in the while loop syntax):
Code:
#!/bin/ksh
sqlplus -s apps/<password> << ENDOFSQL
  define reqid=$REQID;
  spool reqidstatus_log.txt
  select REQUEST_ID,PHASE_CODE,STATUS_CODE
  from fnd_conc_req_summary_v where request_id='106994181' and phase_code='C';
ENDOFSQL

while grep -q "no rows selected" reqidstatus_log.txt
do
  sleep 30
  sqlplus -s apps/<password> << ENDOFSQL
    define reqid=$REQID;
    spool reqidstatus_log.txt
    select REQUEST_ID,PHASE_CODE,STATUS_CODE
    from fnd_conc_req_summary_v where request_id='106994181' and phase_code='C';
ENDOFSQL
done

# 
#  The sqlplus command is succesfully terminated: send mail notification now!
#
<mail command here>
 
Old 10-20-2011, 01:04 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Please use [code][/code] tags around your code, to preserve formatting and to improve readability. Don't use quote tags around code either.

Without them, any extra spacing in your scripts is removed, and those long unbroken lines fore the page to side-scroll, making it hard to read and debug. So go back and edit your posts to fix them.
 
Old 10-20-2011, 03:39 PM   #8
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
The reason your shell program did not work was this line:
Code:
for reqidstatus_log.txt in (grep -l "no rows selected" reqidstatus_log.txt)
What the for does is assign what grep -l returns (a file name) to a variable, in this case, you said the variable was named reqidstatus_log.txt; oops. It should have been something like file, FILE, FILENAME, FILE_NAME or whatever for later use (I used file in the example). After the assignment, it's referred to as ${file} (or whatever).

Looking at your shell program, I would do this:
Code:
#!/bin/ksh
print "Script To check request id status"
#       execute query with a here-is
sqlplus -s apps/<password> << ENDOFSQL
        define reqid=$REQID;
        spool reqidstatus_log.txt
        select REQUEST_ID,PHASE_CODE,STATUS_CODE
        from fnd_conc_req_summary_v where request_id='106994181' and phase_code='C';
ENDOFSQL
#       query has completed, now check the log
for file in (grep -l "no rows selected" reqidstatus_log.txt)
do
        print "no rows selected from reqidstatus_log.txt" \
                | mailx -s "No Rows in ${file}" who@where.what
done
print "emailing spoolfiles"
uuencode reqidstatus_log.txt reqidstatus_log.txt |\
        mailx -s "reqidstatus_log.txt" who@where.what
print "Finished request id status check"
exit
This presupposes that you're only going to execute this once and that the SQL query is not in a loop; i.e., it's a single-pass, query followed by the e-mailing of the result; it simply looks like that's what you're trying to accomplish. Of course you'd want to replace "who@where.what" with a real e-mail address, but this ought to work for you.

Hope this helps some.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
[SOLVED] Bash - While Loop reading from two lists simultaneously - nested while loop wolverene13 Programming 11 10-01-2011 05:00 PM
for loop or while loop to read the fields of a file.. visitnag Linux - Newbie 10 09-02-2010 08:47 PM
bash loop within a loop for mysql ops br8kwall Programming 10 04-30-2008 03:50 AM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 07:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration