Thursday, June 25, 2015

Connecting to SQL Server from Linux/Unix using Perl DBI



Connecting to SQL Server from Linux using Perl DBI

Download Software Components

Perl DBI Module   :DBI-1.633.tar
http://search.cpan.org/CPAN/authors/id/T/TI/TIMB/DBI-1.633.tar.gz

Download FreeTDS :freetds-stable.tar
http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz

Perl DBD::Sybase Module :DBD-Sybase-1.15.tar
http://search.cpan.org/CPAN/authors/id/M/ME/MEWP/DBD-Sybase-1.15.tar.gz


Install DBI

1 - DBI-1.633.tar

perl Makefile.PL
make
make install

Install FreeTDS

2 - freetds-stable.tar

./configure --with-tdsver=7.0 --prefix=/usr/local/freetds
perl Makefile.PL
make
make install

Install DBD-Sybase

3 - DBD-Sybase-1.15.tar

# set||export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:/usr/local/freetds/lib
# set||export SYBASE=/usr/local/freetds

perl Makefile.PL
Use 'CHAINED' mode by default (Y/N) [Y]: Y
Use the threaded (lib..._r) libraries [N]: N
Sybase server to use (default: SYBASE): 192.168.0.98
User ID to log in to Sybase (default: sa): sa
Password (default: undef): 12345678
Sybase database to use on 192.168.0.98 (default: undef): TESTDB
make
make install

Configure FreeTDS

# vim /usr/local/freetds/etc/freetds.conf
       
[TESTDB]
       host = 192.168.0.98
       port = 1433
       tds version = 8.0
       dump file = /tmp/freetds.log
       text size = 64512




SCRIPT TO TEST

#!/usr/bin/perl

use DBI;

my $user   = "userdb";
my $passwd = "12345678";
my $server = "TESTDB";

my $dbh = DBI->connect("DBI:Sybase:server=$server", $user, $passwd, {PrintError => 0});
my $sth;

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";
my $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 ((    $serverName
         , $sqlServerVersion
         , $currentDatabase
         , $currentUser
         , $clientMachine) = $sth->fetchrow) {
   ($sqlServerVersion, @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";
my $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 (($databaseName, $databaseSize) = $sth->fetchrow) {
   printf("    %-40s %20s\n", $databaseName, $databaseSize);  
}
print "\n";
$sth->finish;

print "Disconnecting from SQL Server.\n\n";
$dbh->disconnect;
exit(0);

Sunday, June 7, 2015

How to Enable su root For a Normal User in FreeBSD


root@freebsd:~ # su - andre
When you've made modifications to a file in vi(1) and then find that
you can't write it, type ``<ESC>!rm -f %'' then ``:w!'' to force the
write

This won't work if you don't have write permissions to the directory
and probably won't be suitable if you're editing through a symbolic link.
$ su -
su: Sorry
$ exit
root@freebsd:~ # head /etc/group 
# $FreeBSD: releng/10.1/etc/group 256366 2013-10-12 06:08:18Z rpaulo $
#
wheel:*:0:root
daemon:*:1:
kmem:*:2:
sys:*:3:
tty:*:4:
operator:*:5:root
mail:*:6:
bin:*:7:
root@freebsd:~ # pw usermod andre -G wheel
root@freebsd:~ # head /etc/group
# $FreeBSD: releng/10.1/etc/group 256366 2013-10-12 06:08:18Z rpaulo $
#
wheel:*:0:root,andre
daemon:*:1:
kmem:*:2:
sys:*:3:
tty:*:4:
operator:*:5:root
mail:*:6:
bin:*:7:
root@freebsd:~ # su - andre
If you have a CD-ROM drive in your machine, you can make the CD-ROM that is
presently inserted available by typing 'mount /cdrom' as root.  The CD-ROM
will be available under /cdrom/.  Remember to do 'umount /cdrom' before
removing the CD-ROM (it will usually not be possible to remove the CD-ROM
without doing this.)

Note: This tip may not work in all configurations.
$ su -
Password:

root@freebsd:~ # 

How to install Htop on Freebsd


How to install Htop

#echo ‘linproc /compat/linux/proc linprocfs rw 0 0’  >> /etc/fstab

#echo ‘linux_enable=“YES”’ >> rc.conf

#mkdir -p /usr/compat/linux/proc 

#ln -s /usr/compat /compat

#mount linproc

#cd /usr/ports/emulatost/linux_base-f10 && make install clean

#pkg install sysutils/lsof

#cd /usr/ports/sysutils/htop && make reinstall clean

Tuesday, January 6, 2015

Notebook CCE Ultra Thin N325 Drivers

Notebook CCE Ultra Thin N325 Drivers 


Como dar o Boot correto alterando configurações da BIOS para tirar o Windows 8 e instalar Windows 7.
Segue os Drivers para download de Rede e de Wireless para o Windows 7 32/64bits, FUNCIONA TAMBÉM PARA OUTROS MODELOS CCE.
Link Download 1 https://mega.co.nz/#!jtVBVYyC!BU4uWwO...
Link Download 2 http://www.4shared.com/rar/MRf_hPQmba...

Créditos : https://www.youtube.com/watch?v=Wbd4hnOYogA

Tuesday, December 16, 2014

ORACLE - ORATOP

oratop - Utility for Near Real-time Monitoring of Databases, RAC and Single Instance (Doc ID 1500864.1)


oratop: Release 14.1.2
Usage: 
oratop [ [Options] [Logon] ]

Logon:
{username[/password][@connect_identifier] | / }
[AS {SYSDBA|SYSOPER}]

connect_identifier:
    o Net Service Name, (TNS) or
    o Easy Connect (host[:port]/[service_name])
Options:
    -d : real-time (RT) wait events, section 3 (default is Cumulative)
    -k : FILE#:BLOCK#, section 4 lt is (EVENT/LATCH)
    -m : MODULE/ACTION, section 4 (default is USERNAME/PROGRAM)
    -s : SQL mode, section 4 (default is process mode)
    -c : database service mode (default is connect string) 
    -f : detailed format, 132 columns (default: standard, 80 columns)
    -b : batch mode (default is text-based user interface)
    -n : maximum number of iterations (requires number)
    -i : interval delay, requires value in seconds (default: 5s)
    -v : oratop release version number
    -h : this help


[root@cacti tmp]# ./oratop.RDBMS_11.2_LINUX_X64 siltech/siltech@xe -f -s
Oracle 11g - Primary XE     09:10:05 up: 4.9d,   1 ins,    1 sn,   1 us, 561M mt,    4% fra,   0 er,                      17.1% db
ID %CPU LOAD %DCU   AAS  ASC  ASI  ASW  ASP  AST  UST MBPS IOPS IORL LOGR PHYR PHYW  %FR   PGA TEMP UTPS UCPS SSRT DCTR DWTR  %DBT
 1   23    0   19   0.7    2    0    0    0    2    2    0   40  42u  15k    0    0   96   63M  13M    0  141 244u  116    0   100

EVENT (C)                                                         TOTAL WAITS   TIME(s)  AVG_MS  PCT                    WAIT_CLASS
DB CPU                                                                             4580           59                              
resmgr:cpu quantum                                                     144969      2211    15.3   28                     Scheduler
log file parallel write                                                249928       414     1.7    5                    System I/O
log file sync                                                          186382       408     2.2    5                        Commit
control file parallel write                                            151533       211     1.4    3                    System I/O

ID  USERNAME  MODULE   ACTION  SQL_ID          SQL_TEXT               X  ELAP  CPUT  IOWT  WAIT  EXEC  ROWS  BUFG  DISK  BH%  LOAD
 1  LAURA     perl@ca          74vma1wu3pf7w   select * from all_tab  S   26m   25m    3u     0  4.3k   119   862     0  100     1

[root@cacti ~]# su - oracle
-bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Tue Dec 16 09:23:58 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production


SQL> select sql_text from v$sql where sql_id='74vma1wu3pf7w' union select username from v$session where sql_id='74vma1wu3pf7w';


SQL_TEXT
------------------------------------------------------------------------------------------------------------------------
LAURA
select * from all_tables


SQL> /





[oracle@orasrvteste ]$ ./oratop.RDBMS_11.2_LINUX_X64 -h
./oratop.RDBMS_11.2_LINUX_X64: error while loading shared libraries: libclntsh.so.11.1: cannot open shared object file: No such file or directory
[oracle@orasrvteste lib]$ cd $ORACLE_HOME/lib
[oracle@orasrvteste lib]$export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;
[oracle@orasrvteste lib]$ ll libclntsh.so*
lrwxrwxrwx 1 oracle oinstall       17 May 14  2010 libclntsh.so -> libclntsh.so.10.1
-rwxrwx--- 1 oracle oinstall 20651386 May 14  2010 libclntsh.so.10.1
[oracle@orasrvteste lib]$ cp libclntsh.so.10.1 libclntsh.so.11.1
[oracle@orasrvteste lib]$ oratop.RDBMS_11.2_LINUX_X64 -h
oratop: Release 14.1.2
Usage:
         oratop [ [Options] [Logon] ]

         Logon:
                {username[/password][@connect_identifier] | / }
                [AS {SYSDBA|SYSOPER}]

                connect_identifier:
                     o Net Service Name, (TNS) or
                     o Easy Connect (host[:port]/[service_name])
         Options:
             -d : real-time (RT) wait events, section 3 (default is Cumulative)
             -k : FILE#:BLOCK#, section 4 lt is (EVENT/LATCH)
             -m : MODULE/ACTION, section 4 (default is USERNAME/PROGRAM)
             -s : SQL mode, section 4 (default is process mode)
             -c : database service mode (default is connect string)
             -f : detailed format, 132 columns (default: standard, 80 columns)
             -b : batch mode (default is text-based user interface)
             -n : maximum number of iterations (requires number)
             -i : interval delay, requires value in seconds (default: 5s)
             -v : oratop release version number
             -h : this help

[oracle@orasrvteste lib]$

Thursday, December 11, 2014

PERL - LINUX CONNECT SQLServer

[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]# 

ORACLE - ORA-00205: error in identifying control file

[root@cacti XE]# su - oracle
-bash-4.1$ ls
admin  connect  diag  exit  fast_recovery_area  oradata  oradiag_oracle  product
-bash-4.1$ cd oradata/
-bash-4.1$ cd XE/
-bash-4.1$ ls
control.dbf  sysaux.dbf  system.dbf  temp.dbf  undotbs1.dbf  users.dbf
-bash-4.1$ ll
total 1285700
-rw-r-----. 1 oracle dba   9748480 Dec 10 07:11 control.dbf
-rw-r-----. 1 oracle dba 744497152 Dec 10 07:10 sysaux.dbf
-rw-r-----. 1 oracle dba 377495552 Dec 10 07:10 system.dbf
-rw-r-----. 1 oracle dba  20979712 Dec  9 22:00 temp.dbf
-rw-r-----. 1 oracle dba  78651392 Dec 10 07:05 undotbs1.dbf
-rw-r-----. 1 oracle dba 104865792 Dec  8 12:41 users.dbf
-bash-4.1$ pwd
/u01/app/oracle/oradata/XE
-bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Thu Dec 11 10:47:30 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-00205: error in identifying control file, check alert log for more info


SQL> alter system set control_files='/u01/app/oracle/oradata/XE/control.dbf' scope=spfile;

System altered.

SQL> startup force;
ORACLE instance started.

Total System Global Area  521936896 bytes
Fixed Size     2228080 bytes
Variable Size   322961552 bytes
Database Buffers   192937984 bytes
Redo Buffers     3809280 bytes
Database mounted.
Database opened.

SQL> select * from v$instance;

INSTANCE_NUMBER INSTANCE_NAME
--------------- ----------------
HOST_NAME
----------------------------------------------------------------
VERSION   STARTUP_T STATUS PAR THREAD# ARCHIVE LOG_SWITCH_WAIT
----------------- --------- ------------ --- ---------- ------- ---------------
LOGINS   SHU DATABASE_STATUS INSTANCE_ROLE     ACTIVE_ST BLO EDITION
---------- --- ----------------- ------------------ --------- --- -------
      1 XE
cacti.siltechconsult.com.br
11.2.0.2.0   11-DEC-14 OPEN NO       1 STOPPED
ALLOWED    NO  ACTIVE PRIMARY_INSTANCE   NORMAL    NO  XE



SQL>