Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to execute oracle utility within perl script

Status
Not open for further replies.

netrookie

Technical User
Jul 6, 2003
29
US
Hi, I'm trying to call an Oracle database utility within a perl script. Initially, I created the perl script to check some background process on the server. Now, if certain processes exist, I want to launch this database utility. I need help in executing/launching within this script. So far my code works, but I am stuck in launching oracle export utility. Basically, I check for certain conditions, if both are true (1), run oracle utility. For testing, the third condition is set (0,1) where one of the nodes is down, but what happens is the exp utility executes and it shouldn't. It should only execute under first condition, (both ==1). Can someone help? Thank you.

============================================================
my $checkrpc1= `ps -ef|grep rpc.statd |grep -v grep|wc -l`;
my $checkrpc2= `ssh node2 ps -ef|grep rpc.statd |grep -v grep|wc -l`;

# Running datapump
my $expdp=`/home/oracle/product/11.1.0.6.0/bin/expdp parfile=/home/oracle/param/TST.par`;

if (($checkrpc1 == 1) && ($checkrpc2 == 1)) {
print qq (\nBoth NFS rpc daemons are UP. $date);
send_email("Both NFS rpc daemons are UP. $date");
#$expdp; ##Stuck here..
} elsif (($checkrpc1 == 1) && ($checkrpc2 == 0)) {
print qq (\nNFS rpc daemon on node 2 is down. $date);
send_email("NFS rpc daemon on node 2 is down. $date");
} elsif (($checkrpc1 == 0) && ($checkrpc2 == 1)) {
print qq (\nNFS rpc daemon on node 1 is down. $date);
send_email("NFS rpc daemon on node 1 is down. $date");
} elsif (($checkrpc1 == 0) && ($checkrpc2 == 0)) {
print qq (\nBoth NFS rpc daemons are down. $date);
send_email("Both NFS rpc daemons are down. $date");
} else {
print qq (\nError in status of rpc daemon.Check it out. $date);
send_email("Error in status of rpc daemon.Check it out. $date");
}
 
Then put it inside the condition its supposed to run in. Right now you have it running before any of the conditions are even checked.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I thought using my $variablename is just declaring the variable? I did put in the condition I wanted it to run (its commented out), but it didn't work. So are you saying declare and run in the same condition?

 
From the code you posted it looks like you are using backtiks ``:

Code:
my $expdp=`/home/oracle/product/11.1.0.6.0/bin/expdp parfile=/home/oracle/param/TST.par`;

That runs the application and returns any output to the variable. If those are not actually backtiks then you would use backtiks (or qx{}) to run the application.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
So, comment out the my declaration for this and replace with a quote? Like this?

my $expdp='/home/oracle/product/11.1.0.6.0/bin/expdp parfile=/home/oracle/param/TST.par';

if (($checkrpc1 == 1) && ($checkrpc2 == 1)) {
print qq (\nBoth NFS rpc daemons are UP. $date);
send_email("Both NFS rpc daemons are UP. $date");
qx{$expdp};
} elsif (($checkrpc1 == 1) && ($checkrpc2 == 0)) {
print qq (\nNFS rpc daemon on node 2 is down. $date);
send_email("NFS rpc daemon on node 2 is down. $date");
 
If you want to run the application but not get any output back from it, use the system() function instead of qx{}.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top