- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Reading variable from SQL to Unix
Operating System - HP-UX
1822727
Members
3842
Online
109644
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 12:30 PM
тАО09-17-2009 12:30 PM
Reading variable from SQL to Unix
Hi,
I have a korn shell script and a variable that I'm trying to load data into from a table in Oracle, this variable will then be used in a subject line in an email that will be sent from Unix. I have this so far but am having difficulty still trying to get the variable to display properly in the mail -s command. Can someone please help? Here is the code that only returns '0' in the subject line but I want to actually return the output from the SQL statement into that variable then display it in the Subject line of the Unix mail:
#!/bin/ksh
#COMMENT
. /apps/ppa/bin/.profile
#export ORACLE_HOME=
#export PATH=$PATH:$ORACLE_HOME/bin
export emailadd1=firstname.lastname@email.com
export VAR=0
sqlplus /nolog << EOF
connect opcppa/oracle
set echo off;
set termout on;
set linesize 100;
set pagesize 60;
set newpage 0;
set heading off;
set feedback off;
spool /tmp/output.lis;
select COMPANY into "$VAR" from CUSTOMERS where rownum<2;
spool off;
EOF
/usr/bin/uuencode /tmp/output.lis "TestFileOracleData.txt"|mail -s "$VAR" $emailadd1
#End-of-Script
Thanks!
I have a korn shell script and a variable that I'm trying to load data into from a table in Oracle, this variable will then be used in a subject line in an email that will be sent from Unix. I have this so far but am having difficulty still trying to get the variable to display properly in the mail -s command. Can someone please help? Here is the code that only returns '0' in the subject line but I want to actually return the output from the SQL statement into that variable then display it in the Subject line of the Unix mail:
#!/bin/ksh
#COMMENT
. /apps/ppa/bin/.profile
#export ORACLE_HOME=
#export PATH=$PATH:$ORACLE_HOME/bin
export emailadd1=firstname.lastname@email.com
export VAR=0
sqlplus /nolog << EOF
connect opcppa/oracle
set echo off;
set termout on;
set linesize 100;
set pagesize 60;
set newpage 0;
set heading off;
set feedback off;
spool /tmp/output.lis;
select COMPANY into "$VAR" from CUSTOMERS where rownum<2;
spool off;
EOF
/usr/bin/uuencode /tmp/output.lis "TestFileOracleData.txt"|mail -s "$VAR" $emailadd1
#End-of-Script
Thanks!
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 12:50 PM
тАО09-17-2009 12:50 PM
Re: Reading variable from SQL to Unix
sqlplus does NOT understand shell variables.
Its only communication channel back is really STDOUT data, and for numerics in a pinch the process exit status.
Google for "sqlplus select into shell variable"
You'll get a lot of useful example.
For example you find a construct like:
#!/bin/sh
COUNT=`sqlplus -s system/manager < set head off;
select count(*) from table1;
exit;
ABC`
[ I'd use the preferred $( ... ) ]
For more than one number you'll need the help of the Shell READ command and perhaps toss in an AWK or PERL filter.
So please play with that thought for a while and see if you need further help!
hth,
Hein van den Heuvel.
Its only communication channel back is really STDOUT data, and for numerics in a pinch the process exit status.
Google for "sqlplus select into shell variable"
You'll get a lot of useful example.
For example you find a construct like:
#!/bin/sh
COUNT=`sqlplus -s system/manager <
select count(*) from table1;
exit;
ABC`
[ I'd use the preferred $( ... ) ]
For more than one number you'll need the help of the Shell READ command and perhaps toss in an AWK or PERL filter.
So please play with that thought for a while and see if you need further help!
hth,
Hein van den Heuvel.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 01:13 PM
тАО09-17-2009 01:13 PM
Re: Reading variable from SQL to Unix
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2009 06:28 AM
тАО09-18-2009 06:28 AM
Re: Reading variable from SQL to Unix
Thanks,
I will look at these and others on google.
I will look at these and others on google.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP