RE: Script to test connecting to Oracle DBs

2012-08-01 Thread Martin Gainty

#!/bin/sh
C:/grep/grep.exe -S (SERVICE_NAME = tnsnames.ora  service.ora
rm -r new.ora
echo #!/bin/sh  tns_ping.sh
C:/cygwin/bin/sed.exe 's/(SERVICE_NAME \=/tnsping.exe /' 
service.oratns_ping.sh
vi tns_ping.sh

If you find There is a way to pipe the 2 commands let me know but for now this 
little shell script works  

Martin
___ 
Jogi és Bizalmassági kinyilatkoztatás/Verzicht und 
Vertraulichkeitanmerkung/Note de déni et de confidentialité
 Ez az
üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy
jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának
készítése nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és
semmiféle jogi alkalmazhatósága sincs.  Mivel az electronikus üzenetek
könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet
ezen üzenet tartalma miatt.

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger 
sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung 
oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem 
Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. 
Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung 
fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le 
destinataire prévu, nous te demandons avec bonté que pour satisfaire informez 
l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est 
interdite. Ce message sert à l'information seulement et n'aura pas n'importe 
quel effet légalement obligatoire. Étant donné que les email peuvent facilement 
être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité 
pour le contenu fourni.


 Date: Sat, 28 Jul 2012 13:45:18 +1200
 Subject: Script to test connecting to Oracle DBs
 From: newbie01.p...@gmail.com
 To: beginners@perl.org; dbi-us...@perl.org
 
 Hi all,
 
 I am looking for a Perl script or something similar that I can use to test
 connection from a client PC to several databases on a server.
 
 Does anyone know of any such script lying around somewhere :(-
 
 Currently, am testing connection from a client PC to an Oracle DB using
 Oracle's sqlplus. All is well and good until I have to test connection to
 multiple databases on the server.
 
 So I am hoping to use a Perl script that I can use which will parse some
 sort of config file that contains hostname.tns_alias combination and then
 test connection to the Oracle DB and run a simple SQL like SELECT COUNT(1)
 from USER_TABLES, if I get an error, that means there is an issue
 connection to that database, otherwise all is good.
 
 At the moment, easiest I can think of using Perl's system command to run
 sqlplus. Or is it better to look at using DBI? Would be very much
 appreciated if someone can provide me a simple DBI script to start with if
 that is the best approach to use.
 
 Any suggestion/advice much appreciated. Thanks in advance.
  

Re: Script to test connecting to Oracle DBs

2012-08-01 Thread Leo Susanto
use strict;
use DBI;
use DBD::Oracle qw(:ora_types);

my $user   = '';
my $passwd = '';
my $tnsName = '';

$ENV{'ORACLE_HOME'} = 'C:\oracle\product\10.2.0\client_1';
my $dbh = DBI-connect(dbi:Oracle:$tnsName, $user, $passwd);
my $SQL = qq{ SELECT XXX};

my $sth0 = $dbh-prepare($SQL);
print SQL is prepared;\n;
$sth0-execute();
print SQL is executed;\n;
$sth0-finish();


On Fri, Jul 27, 2012 at 6:45 PM, newbie01 perl newbie01.p...@gmail.com wrote:
 Hi all,

 I am looking for a Perl script or something similar that I can use to test
 connection from a client PC to several databases on a server.

 Does anyone know of any such script lying around somewhere :(-

 Currently, am testing connection from a client PC to an Oracle DB using
 Oracle's sqlplus. All is well and good until I have to test connection to
 multiple databases on the server.

 So I am hoping to use a Perl script that I can use which will parse some
 sort of config file that contains hostname.tns_alias combination and then
 test connection to the Oracle DB and run a simple SQL like SELECT COUNT(1)
 from USER_TABLES, if I get an error, that means there is an issue
 connection to that database, otherwise all is good.

 At the moment, easiest I can think of using Perl's system command to run
 sqlplus. Or is it better to look at using DBI? Would be very much
 appreciated if someone can provide me a simple DBI script to start with if
 that is the best approach to use.

 Any suggestion/advice much appreciated. Thanks in advance.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Script to test connecting to Oracle DBs

2012-07-27 Thread Rob Dixon
On 28/07/2012 02:45, newbie01 perl wrote:
 Hi all,
 
 I am looking for a Perl script or something similar that I can use to test
 connection from a client PC to several databases on a server.
 
 Does anyone know of any such script lying around somewhere :(-
 
 Currently, am testing connection from a client PC to an Oracle DB using
 Oracle's sqlplus. All is well and good until I have to test connection to
 multiple databases on the server.
 
 So I am hoping to use a Perl script that I can use which will parse some
 sort of config file that contains hostname.tns_alias combination and then
 test connection to the Oracle DB and run a simple SQL like SELECT COUNT(1)
 from USER_TABLES, if I get an error, that means there is an issue
 connection to that database, otherwise all is good.
 
 At the moment, easiest I can think of using Perl's system command to run
 sqlplus. Or is it better to look at using DBI? Would be very much
 appreciated if someone can provide me a simple DBI script to start with if
 that is the best approach to use.
 
 Any suggestion/advice much appreciated. Thanks in advance.

I'm not clear why sqlplus won't let you connect to multiple databases,
assuming you don't want to connect to them all /simultaneously/?

I would say you were better off using the DBI module, and you will also
need the SBS::Oracle driver module. The documentation

http://metacpan.org/module/DBI
http://metacpan.org/module/DBD::Oracle

is very extensive, but the basic idea looks like the program below.

I hope this helps.

Rob


use strict;
use warnings;

use DBI;

autoflush STDOUT;

my ($user, $pass) = qw/ username  password /;

my @databases = qw/ db1 db2 db3 db4 /;

for my $dbname (@databases) {

  print Database: $dbname\n;

  my $dbh = DBI-connect(dbi:Oracle:$dbname, $user, $pass,
  { PrintError = 1, PrintWarn = 1 } );
  
  next unless $dbh;

  my ($count) = $dbh-selectrow_array('SELECT COUNT(*) FROM user_tables');
  print Database $dbname: Count: $count\n;
}

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/