0

Prevent printing exception in my perl script. in Exception original DB password is being printed so i'm trying to suppress it.

I have already tried system("$sql1 &2>dev/null") but it is not help full

    sub somefunc{
    my sql1 = sqlplus -S $user_name/$password\@$TNSname $sqlfilename     $somestring;
    system(sql1);
    }
    Exception : 
    some time $somestring is coming with character like '>' and '(' so >im         getting 
    sh: -c: line 0: syntax error near unexpected token `>'
    sh: -c: line 0: `sqlplus USERNAME/RAWPASSWORD@TNSNAME >@log.sql somescript.sh >>> Start time:           
    Sun #Jul 21 20:33:09 CDT 2019' 

In above error the RAWPASSWORD is being printed in logs so i am
trying to avoid it

Guru prasath
  • 23
  • 1
  • 7

2 Answers2

0

The best solution is probably not to use sqlplus to access your database. you should, instead, look at DBI and DBD::Oracle.

Dave Cross
  • 68,119
  • 3
  • 51
  • 97
  • Thanks Dave, But we have both connections actually we are using sqlplus only for multi threading in my perl script for normal flow we use DBI only – Guru prasath Aug 13 '19 at 09:32
  • @Guruprasath: I'm not sure how that is relevant. If you don't want to put the password in the logs, then don't use a method that prints the password to the logs :-) – Dave Cross Aug 13 '19 at 10:01
0

I would suggest using qx// or IPC::Open3 but if that's not feasible try something like below:

sub somefunc {
   my $sql1 = "sqlplus -S $user_name/$password\@$TNSname $sqlfilename $somestring";
   my @msg = qx/$sql1 2>&1/;
}

and then read the output in @msg and action accordingly.

Must read - What's the difference between Perl's backticks, system, and exec?

Ashish Kumar
  • 811
  • 4
  • 8