Solaris / OpenSolarisThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
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
#!/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 ?
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
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.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.