- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Call sqlplus with exec command FROM PERL
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
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
Community
Resources
Forums
Blogs
- 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
тАО02-25-2005 08:26 AM
тАО02-25-2005 08:26 AM
I want to call sqlplus from Perl, but passing parameters, I do not want use DBI, it's a simple call.. What shoud I correct?
Notes:
1. Remember, Oracle end each command with ';' like perl.
2. I want to mix variables, inside oracle command put perl variables, see below.
3. The output from sql command is redirected to a file out_file, see below.
For each line en the file, call sqlplus and execute one command but passing variables from perl.
If you think... it's better with unix shell rather than perl, I accepted too.
#!/usr/bin/perl
open(INFILE,"salida");
while (
$user=~substr($_,1,20);
$vday=~substr($_,22,8);
$vtime=~substr($_,32,8);
exec 'sqlplus',
' << OEF
connect system/manager;
select username,status
from v$session
where username = $user
and logon_time = $vday$time;
EOF
' > out_file.txt;
}
close(INFILE);
Thanks for your time...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2005 09:09 AM
тАО02-25-2005 09:09 AM
Re: Call sqlplus with exec command FROM PERL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2005 09:12 AM
тАО02-25-2005 09:12 AM
Re: Call sqlplus with exec command FROM PERL
here is how I am doing it in a ksh.
sqlplus /nolog << eof
connect ${usr}
column file_name format a55
column member format a55
set pagesize 0
select file_name from dba_data_files
order by file_name
/
select member from v\$logfile
order by member
/
exit
eof
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-26-2005 12:56 AM
тАО02-26-2005 12:56 AM
Solution$username = "SAPLNX";
$command = "select status from v\\\$session where username = '${username}';";
foreach (`echo "$command" | sqlplus -s "/ as sysdba"`) {
print "-- $_";
}
For somewhat more elaborate work I would create an sqlplus script that takes params.
For even more advanced work I'd 'OPEN' a sqlplus command: open (SQL ,"sqlplus..|")
Redirect output to a file and feed commands.
Later parse the file.
Or... generate a sqplus script and open a sqplus session for output (backticks again?)
For full control of input and output you'll need a fork and wait and stuff.
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-26-2005 08:39 AM
тАО02-26-2005 08:39 AM
Re: Call sqlplus with exec command FROM PERL
On re-visit I noticed that you intend to invoke sqlplus once for each line in 'salida'. That's rather clumsy.
Why not have SQLplus/Oracle do it all?
Define an EXTERNAL TABLE over 'salida' and just JOIN with SQL statements.
Here is a simplified example:
First...
CREATE OR REPLACE DIRECTORY salida_dir AS '/tmp';
CREATE TABLE salida_exernal (username VARCHAR (20))
ORGANIZATION EXTERNAL (
DEFAULT DIRECTORY salida_dir
ACCESS PARAMETERS ( records delimited by newline)
LOCATION ('salida.dat')
);
Next just execute the appropriate procedure over the tables:
cat > /tmp/test.sql
select status, s.username
from v$session s, salida_external e
where s.username = e.username;
:
order..
;
back to perl (or shell)
$foreach (`sqlplus -s "/ as sysdba" @/tmp/test.sql`){
... your result processing ...
}
This way you can create and maintain the more or less complex join in a seperate .sql file. You could of course also stick it in a string as per earlier reply.
You'll have to create the external table definition to match the data of course. I did not test this, but I think the actuall definition you need is something like:
CREATE TABLE salida_exernal (
username VARCHAR (20),
fill_1 CHAR (1),
vday VARCHAR (8),
fill_2 CHAR (1),
vtime VARCHAR (8))
:
Enjoy!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-26-2005 10:48 AM
тАО02-26-2005 10:48 AM
Re: Call sqlplus with exec command FROM PERL
I like to "hide" the login information ("system/manager") -- preferably by prompting the user. Next choice is creating an Oracle account with just enough permissions to do what's needed. Last choice, and I've had to do this, is create a file that's only readable by the user that runs the script and embed the information there.
As to shell vs Perl -- I guess part of that depends on other sysadmins at your site. If they know Perl, more power to you. If they don't, shell might be better so that you're not the only one who knows how to do it.
HTH,
Mic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-26-2005 01:11 PM
тАО02-26-2005 01:11 PM
Re: Call sqlplus with exec command FROM PERL
Also... always consider turning things around :-)
Given that the query action desired is trivial,
you might just want to do it all in perl. Untested:
#!/usr/bin/perl
$command = "select username, logon_time, status from v\\\$session;"
foreach (`echo "$command" | sqlplus -s "/ as sysdba"`) {
($user,$logon,$status} = split;
$session{$logon.$user} = $status;
}
open (INFILE,"
while (
$user=~substr($_,1,20);
$vday=~substr($_,22,8);
$vtime=~substr($_,32,8);
$status = $session{$vday.$vtime.$user};
print OUT_FILE "$user $vday $vtime $status\n" if $status;
}
grins,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2005 12:51 AM
тАО02-28-2005 12:51 AM