[root@cacti SQLServer]# ./sql_connect.pl
Successful Connection.
Current Connection Properties
---------------------------------------------------------------------------------------
SQL Server Instance : SRV-DB
SQL Server Version : Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
Current Database : master
Current User : sa
Client Machine : blogger.blogger.com.br
Available Databases
-----------------------------------------------------------------
DATABASE 35178.13 MB
DTBTESTE 35178.13 MB
DBTTESTE2 32835.31 MB
MSSQL SYSTEM RESOURCE 61.06 MB
msdb 21.25 MB
ReportServer 17.81 MB
tempdb 8.50 MB
master 8.13 MB
ReportServerTempDB 3.06 MB
model 3.00 MB
Disconnecting from SQL Server.
[root@cacti SQLServer]# cat sql_connect.pl
#!/usr/bin/perl -w
use warnings;
use strict;
use DBI;
my $user = "sa";
my $passwd = "passwd";
my $server = "122.128.0.0";
my $dbh = DBI->connect("DBI:Sybase:server=$server", $user, $passwd, {PrintError => 0});
my $sth;
my $sqlStatement;
unless ($dbh) {
die "ERROR: Failed to connect to server ($server).\nERROR MESSAGE: $DBI::errstr";
} else {
print "\n";
print "Successful Connection.";
print "\n\n";
}
print "Current Connection Properties\n";
print "---------------------------------------------------------------------------------------\n";
$sqlStatement = "select \@\@servername, \@\@version, db_name(), system_user, host_name()";
unless ($sth = $dbh->prepare($sqlStatement)) {
$dbh->disconnect;
die "ERROR: Failed to prepare SQL statement.\nSQL: $sqlStatement\nERROR MESSAGE: $DBI::errstr";
}
unless ($sth->execute) {
$dbh->disconnect;
die "ERROR: Failed to execute query.\nSQL: $sqlStatement\nERROR MESSAGE: $DBI::errstr";
}
while (( my $serverName, my $sqlServerVersion, my $currentDatabase, my $currentUser, my $clientMachine ) = $sth->fetchrow) {
(my $sqlServerVersion, my @dummy) = split(/\n/, $sqlServerVersion);
print " SQL Server Instance : $serverName\n";
print " SQL Server Version : $sqlServerVersion\n";
print " Current Database : $currentDatabase\n";
print " Current User : $currentUser\n";
print " Client Machine : $clientMachine\n";
}
print "\n";
$sth->finish;
print "Available Databases\n";
print "-----------------------------------------------------------------\n";
$sqlStatement = "select isnull(db_name(dbid), 'MSSQL SYSTEM RESOURCE') as Name,
str(convert(dec(15),sum(size))* 8192/ 1048576,10,2)+ N' MB' as Size
from sys.sysaltfiles group by dbid order by 2 desc";
unless ($sth = $dbh->prepare($sqlStatement)) {
$dbh->disconnect;
die "ERROR: Failed to prepare SQL statement.\nSQL: $sqlStatement\nERROR MESSAGE: $DBI::errstr";
}
unless ($sth->execute) {
$dbh->disconnect;
die "ERROR: Failed to execute query.\nSQL: $sqlStatement\nERROR MESSAGE: $DBI::errstr";
}
while (( my $databaseName, my $databaseSize) = $sth->fetchrow) {
printf(" %-40s %20s\n", $databaseName, $databaseSize);
}
print "\n";
$sth->finish;
print "Disconnecting from SQL Server.\n\n";
$dbh->disconnect;
exit(0);
[root@cacti SQLServer]#
---------------------------------------------------------------------------------------
SQL Server Instance : SRV-DB
SQL Server Version : Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
Current Database : master
Current User : sa
Client Machine : blogger.blogger.com.br
-----------------------------------------------------------------
DATABASE 35178.13 MB
DTBTESTE 35178.13 MB
DBTTESTE2 32835.31 MB
MSSQL SYSTEM RESOURCE 61.06 MB
msdb 21.25 MB
ReportServer 17.81 MB
tempdb 8.50 MB
master 8.13 MB
ReportServerTempDB 3.06 MB
model 3.00 MB
#!/usr/bin/perl -w
use warnings;
use strict;
my $passwd = "passwd";
my $server = "122.128.0.0";
my $sth;
die "ERROR: Failed to connect to server ($server).\nERROR MESSAGE: $DBI::errstr";
} else {
print "\n";
print "Successful Connection.";
print "\n\n";
}
print "---------------------------------------------------------------------------------------\n";
$sqlStatement = "select \@\@servername, \@\@version, db_name(), system_user, host_name()";
unless ($sth = $dbh->prepare($sqlStatement)) {
$dbh->disconnect;
die "ERROR: Failed to prepare SQL statement.\nSQL: $sqlStatement\nERROR MESSAGE: $DBI::errstr";
}
unless ($sth->execute) {
$dbh->disconnect;
die "ERROR: Failed to execute query.\nSQL: $sqlStatement\nERROR MESSAGE: $DBI::errstr";
}
while (( my $serverName, my $sqlServerVersion, my $currentDatabase, my $currentUser, my $clientMachine ) = $sth->fetchrow) {
(my $sqlServerVersion, my @dummy) = split(/\n/, $sqlServerVersion);
print " SQL Server Version : $sqlServerVersion\n";
print " Current Database : $currentDatabase\n";
print " Current User : $currentUser\n";
print " Client Machine : $clientMachine\n";
}
$sth->finish;
print "Available Databases\n";
print "-----------------------------------------------------------------\n";
$sqlStatement = "select isnull(db_name(dbid), 'MSSQL SYSTEM RESOURCE') as Name,
str(convert(dec(15),sum(size))* 8192/ 1048576,10,2)+ N' MB' as Size
from sys.sysaltfiles group by dbid order by 2 desc";
unless ($sth = $dbh->prepare($sqlStatement)) {
$dbh->disconnect;
die "ERROR: Failed to prepare SQL statement.\nSQL: $sqlStatement\nERROR MESSAGE: $DBI::errstr";
}
unless ($sth->execute) {
$dbh->disconnect;
die "ERROR: Failed to execute query.\nSQL: $sqlStatement\nERROR MESSAGE: $DBI::errstr";
}
while (( my $databaseName, my $databaseSize) = $sth->fetchrow) {
printf(" %-40s %20s\n", $databaseName, $databaseSize);
}
$sth->finish;
print "Disconnecting from SQL Server.\n\n";
$dbh->disconnect;
exit(0);
[root@cacti SQLServer]#
0 comentários:
Post a Comment