Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, November 3, 2015

Trying to get source code of a webpage in PERL

use strict;
use warnings;
use LWP::Simple;

print "ExaCodigo\tEctCodigo\tExcCodigo\tTUSS\tSQL";

open(IN,'db')or die $!;

while(<IN>){
    chomp;
    my($ExaCodigo,$EctCodigo,$ExcCodigo)=split (/\t/,$_);
    my $link = "http\:\/\/conmedhsaude.com.br\/tuss.php\?c\=\&e\=$ExcCodigo\&p=\&q\=\&consultar\=";
    my $page = get($link) or die "cannot retrieve code\n";
    $page =~ s/\n//g;
    my $TUSS = $1 if ($page =~ /\sTUSS:\s(\d+)\<\/span\>\s+/);
    unless($TUSS) { $TUSS = 'null' }
    print "$ExaCodigo\t$EctCodigo\t$ExcCodigo\t$TUSS\tinsert into ExameCodigoTipo ExaCodigo      values ($TUSS) where ExaCodigo = $ExaCodigo and EctCodigo = $EctCodigo\n";

}
close(IN); _________________________________________________________________________________
DB 16 1 28061144 23 1 28040350 26 1 28061098 33 1 28050037 44 1 28150082 48 1 28060156 64 1 28061608 65 1 28061667 66 1 28061594 67 1 28061748 69 1 28050070 75 1 28060725 77 1 28060229 81 1 28061756 89 1 28060342 90 1 28100140 102 1 28060423
_________________________________________________________________________________ HTML

<input type="text" id="c" name="c" value="" style="margin-left:40px;" />                    Código AMB:<input type="text" id="e" name="e" value="28040481" style="margin-left:40px;" />                    Descrção TUSS: <input type="text" id="p" name="p" value="" style="margin-left:28px;" />                    Descrção AMB: <input type="text" id="q" name="q" value="" style="margin-left:25px;" />                 <input name="consultar" type="submit" class="botao" value="" style="border:none;" >                        </form>            </div> <div class='linhaguia'></div>             <div class="guiaitemsup">                        <div class="guiaitem">             <span class="nome">Código TUSS: 40304361</span>                <span class="esp"><span class="tit2">Descrição TUSS: HEMOGRAMA COM CONTAGEM DE PLAQUETAS OU FRACOES (ERITROGRAM</span></span>                <span class="end"><b>Código do grupo TUSS: </b>40308<br><b>Grupo TUSS: </b>MEDICINA LABORATORIAL  - IMUNOLOGIA<br><b>Código AMB: </b>28040481<br><b>Descrição AMB: </b>HEMOGRAMA COMPLETO (ERITOGRAMA+LEUCOGRAMA+AVALIACAO DE PLAQ<br></span>            </div>            </div>                                                     <div class="clear"></div> <div id='paginacao'><p class="MyriadCH"><span paginacaobot >1</span></p></div>                     </div>                        <div id="lateral">     <div class="clear"></div>    <!-- <a href="http://177.21.147.100:8086/mvautorizadorguias/" title="Autorizador" target="_blank" class="latitem latitemautorizador" ></a> -->    <a href="http://201.59.94.100:8086/mvautorizadorguias/" title="Autorizador" target="_blank" class="latitem latitemautorizador" ></a>    <a href="tuss.php" title="TUSS" class="latitem latitemtuss" ></a>    <a href="trabalheconosco.php" title="Trabalhe Conosco" class="latitem latitemtrabalhe" ></a>        <a href="perguntasfrequentes.php" title="Perguntas Frequentes" class="latitem latitemperguntas" ></a>    <a href="faleconosco.php" title="Central de Atendimento" class="latitem latitematend" ></a>    <a href="linksuteis.php" title="Links Úteis" class="latitem latitemtels" ></a> <a href="commaissaude.php" title="Com + Saúde" class="latitem latitemprevent" ></a>    <a href="imagens/redecredenciada.pdf" title="Rede Credenciada" target="_blank" class="latitem latitemrede" ></a>    <br><br>       <!-- <div id="abramgeans">        <a href="http://www.abramge.com.br/" target="_blank">        <img src="imagens/site/abramge.png" class="abramge">        </a>            <a href="http://www.ans.gov.br/" target="_blank">        <img src="imagens/site/ans.png" class="ans">        </a>    </div>-->    <div class="clear"></div></div>                        <div class="clear"></div>        </div> <div class="linha"></div> <div id="rodape"> <div class="central">     <a href="http://www.taticaweb.com.br/" class="taticaweb" target="_blank"></a>            <div id="abramgeans1" style="float: left;margin: -9px 0 0 0;">                <a href="http://www.abramge.com.br/" target="_blank">                <img src="imagens/site/abramge.png" class="abramge" width="58" height="41">                </a>                            <a href="http://www.ans.gov.br/" target="_blank">                <img src="imagens/site/ans.png" class="ans" width="" height="39">            </a>       </div>        <div class="rodapeatend">         <span class="cat">Central de Atendimento:</span><span class="tel">(24)4009-4545 | (24)4009-4519</span>         <span class="cat">Central de Vendas:</span><span class="tel">(24)4009-8803</span><br />            <span class="cat" style="padding-top:12px; margin-left:-98px;">SAC:</span><span class="tel">0800-0302015

_________________________________________________________________________________
OUTPUT
ExaCodigo EctCodigo ExcCodigo TUSS SQL

23 1 28040350 null insert into ExameCodigoTipo ExaCodigo values (null) where ExaCodigo = 23 and EctCodigo = 1
26 1 28061098 null insert into ExameCodigoTipo ExaCodigo values (null) where ExaCodigo = 26 and EctCodigo = 1
33 1 28050037 null insert into ExameCodigoTipo ExaCodigo values (null) where ExaCodigo = 33 and EctCodigo = 1
44 1 28150082 null insert into ExameCodigoTipo ExaCodigo values (null) where ExaCodigo = 44 and EctCodigo = 1
48 1 28060156 null insert into ExameCodigoTipo ExaCodigo values (null) where ExaCodigo = 48 and EctCodigo = 1
64 1 28061608 null insert into ExameCodigoTipo ExaCodigo values (null) where ExaCodigo = 64 and EctCodigo = 1
65 1 28061667 null insert into ExameCodigoTipo ExaCodigo values (null) where ExaCodigo = 65 and EctCodigo = 1
66 1 28061594 null insert into ExameCodigoTipo ExaCodigo values (null) where ExaCodigo = 66 and EctCodigo = 1
67 1 28061748 null insert into ExameCodigoTipo ExaCodigo values (null) where ExaCodigo = 67 and EctCodigo = 1
69 1 28050070 null insert into ExameCodigoTipo ExaCodigo values (null) where ExaCodigo = 69 and EctCodigo = 1
75 1 28060725 null insert into ExameCodigoTipo ExaCodigo values (null) where ExaCodigo = 75 and EctCodigo = 1
77 1 28060229 null insert into ExameCodigoTipo ExaCodigo values (null) where ExaCodigo = 77 and EctCodigo = 1
81 1 28061756 null insert into ExameCodigoTipo ExaCodigo values (null) where ExaCodigo = 81 and EctCodigo = 1
89 1 28060342 40306631 insert into ExameCodigoTipo ExaCodigo values (40306631) where ExaCodigo = 89 and EctCodigo = 1 

 

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);

Wednesday, December 10, 2014

ORACLE - ADD DISK ASM/Diskgroup - Automatic Storage Management (ASM)

Automatic Storage Management (ASM)

login as: root
root@192.168.0.239's password:
Last login: Tue Dec  9 19:10:42 2014 from 192.168.0.206
[root@db1 ~]# fdisk -l

Disk /dev/sda: 150.3 GB, 150323855360 bytes
255 heads, 63 sectors/track, 18275 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000dc94c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        4203    33554432   82  Linux swap / Solaris
/dev/sda3            4203        9303    40960000   83  Linux
/dev/sda4            9303       18276    72080384    5  Extended
/dev/sda5            9303       18276    72079360   83  Linux

Disk /dev/sdc: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x90a18a8c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        6527    52428096   83  Linux

Disk /dev/sdd: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x3a45183b

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1        6527    52428096   83  Linux

Disk /dev/sde: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xde587821

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1        6527    52428096   83  Linux

Disk /dev/sdb: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x50b618df

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        6527    52428096   83  Linux

Disk /dev/sdf: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2932987d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdf1               1        6527    52428096   83  Linux

Disk /dev/sdh: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/sdg: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xbe2c0835

   Device Boot      Start         End      Blocks   Id  System
/dev/sdg1               1       26108   209712478+  83  Linux
[root@db1 ~]# fdisk -l /dev/sdh

Disk /dev/sdh: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@db1 ~]# cat /proc/partitions
major minor  #blocks  name

   2        0          4 fd0
  11        0    1048575 sr0
   8        0  146800640 sda
   8        1     204800 sda1
   8        2   33554432 sda2
   8        3   40960000 sda3
   8        4          1 sda4
   8        5   72079360 sda5
   8       32   52428800 sdc
   8       33   52428096 sdc1
   8       48   52428800 sdd
   8       49   52428096 sdd1
   8       64   52428800 sde
   8       65   52428096 sde1
   8       16   52428800 sdb
   8       17   52428096 sdb1
   8       80   52428800 sdf
   8       81   52428096 sdf1
   8      112  104857600 sdh
   8       96  209715200 sdg
   8       97  209712478 sdg1

[root@db1 ~]# fdisk /dev/sdh
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xbe78fa85.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-13054, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054):
Using default value 13054

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@db1 ~]# cat /proc/partitions
major minor  #blocks  name

   2        0          4 fd0
  11        0    1048575 sr0
   8        0  146800640 sda
   8        1     204800 sda1
   8        2   33554432 sda2
   8        3   40960000 sda3
   8        4          1 sda4
   8        5   72079360 sda5
   8       32   52428800 sdc
   8       33   52428096 sdc1
   8       48   52428800 sdd
   8       49   52428096 sdd1
   8       64   52428800 sde
   8       65   52428096 sde1
   8       16   52428800 sdb
   8       17   52428096 sdb1
   8       80   52428800 sdf
   8       81   52428096 sdf1
   8      112  104857600 sdh
   8      113  104856223 sdh1
   8       96  209715200 sdg
   8       97  209712478 sdg1
[root@db1 ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdc (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdd (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sde (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdf (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdg (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
[root@db1 ~]# /etc/init.d/oracleasm listdisks
ASM01
ASM02
ASM03
ASM04
ASM05
[root@db1 ~]# su - oracle
[oracle@db1 ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Wed Dec 10 12:04:36 2014

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

SQL> connect sys as sysdba
Enter password:
Connected to an idle instance.
SQL> quit
Disconnected
[oracle@db1 ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 10-DEC-2014 12:05:09

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                09-DEC-2014 18:35:20
Uptime                    0 days 17 hr. 29 min. 49 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/app/oracle/product/11.2.0/grid/network/admin/listener.ora
Listener Log File         /opt/app/oracle/diag/tnslsnr/db1/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=blogger.blogger.intranet)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
  Instance "+ASM", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@db1 ~]$ lsnrctl stop

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 10-DEC-2014 12:05:17

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
The command completed successfully
[oracle@db1 ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Wed Dec 10 12:05:26 2014

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

SQL> connect sys as sysdba
Enter password:
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.

Total System Global Area 1.5667E+10 bytes
Fixed Size                  2268632 bytes
Variable Size            2113929768 bytes
Database Buffers         1.3522E+10 bytes
Redo Buffers               28127232 bytes
SQL> select name, path from v$asm_disk;

NAME                     PATH
---------------------    ------------------------------------
DSKDATA_0000   /dev/oracleasm/disks/ASM01

DSKDATA_0001   /dev/oracleasm/disks/ASM02

DSKDATA_0002    /dev/oracleasm/disks/ASM03

DSKDATA_0003   /dev/oracleasm/disks/ASM04

DSKDATA_0004   /dev/oracleasm/disks/ASM05


SQL> quit
Disconnected from Oracle Database 11g Release 11.2.0.4.0 - 64bit Production
[oracle@db1 ~]$ su -
Password:
[root@db1 ~]# /etc/init.d/oracleasm createdisk AMS06 /dev/sdh1
Marking disk "AMS06" as an ASM disk:                       [  OK  ]
[root@db1 ~]# su - oracle
[oracle@db1 ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Wed Dec 10 12:10:44 2014

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

SQL> connect sys as sysdba
Enter password:
Connected.
SQL> select path from v$asm_disk;

PATH
--------------------------------------------------------------------------------
/dev/oracleasm/disks/AMS06
/dev/oracleasm/disks/ASM03
/dev/oracleasm/disks/ASM02
/dev/oracleasm/disks/ASM04
/dev/oracleasm/disks/ASM01
/dev/oracleasm/disks/ASM05

6 rows selected.

SQL> select name, total_mb, free_mb from v$asm_diskgroup;

NAME                             TOTAL_MB    FREE_MB
------------------------------ ----------            ----------
DSKDATA                       255995             57

SQL> quit
Disconnected from Oracle Database 11g Release 11.2.0.4.0 - 64bit Production
With the Automatic Storage Management option
[oracle@db1 ~]$ cat /etc/oratab
#Backup file is  /opt/app/oracle/product/11.2.0/grid/srvm/admin/oratab.bak.db1 line added by Agent
#



# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
+ASM:/opt/app/oracle/product/11.2.0/grid:N
TESTE:/opt/app/oracle/product/11.2.0/db_1:N             # line added by Agent
PRD:/opt/app/oracle/product/11.2.0/db_1:N          # line added by Agent
[oracle@db1 ~]$ export ORACLE_SID=+ASM
[oracle@db1 ~]$ export ORACLE_HOME=/opt/app/oracle/product/11.2.0/grid
[oracle@db1 ~]$ export PATH=$ORACLE_HOME/bin:$PATH
[oracle@db1 ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Wed Dec 10 12:13:09 2014

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

SQL> connect sys as sysasm
Enter password:
Connected.
SQL> alter diskgroup DSKDATA add disk '/dev/oracleasm/disks/AMS06';

Diskgroup altered.

SQL> quit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Automatic Storage Management option
[oracle@db1 ~]$ export ORACLE_SID=PROD
[oracle@db1 ~]$ export ORACLE_HOME=/opt/app/oracle/product/11.2.0/db_1
[oracle@db1 ~]$ export PATH=$ORACLE_HOME/bin:$PATH
[oracle@db1 ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Wed Dec 10 12:17:15 2014

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

SQL> connect sys as sysdba
Enter password:
Connected.
SQL> select name, total_mb, free_mb from v$asm_diskgroup;

NAME                             TOTAL_MB    FREE_MB
------------------------------ ----------            ----------
DSKDATA                       358393              102453

SQL>



 

ORACLE - Swiss penknife QUERY


Swiss penknife QUERY

SHOW AND KILL USER CONNECTED 

SQL> alter system kill session ''' ||sid|| ',' || serial#|| ''' immediate;' from v$session where username='TESTE';

SHOW SIZE BY DATAFILE

SQL> select file_id, block_id, blocks*8192/1024 MB,
owner || '.' || segment_name "Name", block_id*8192/1024 "Position MB"
from  sys.dba_Extents
where file_id = &&fileid
union
select file_id, block_id, blocks*8192/1024, 'Free' "Name", block_id*8192/1024 "P
osition MB"
from sys.dba_free_space
where file_id = &fileid
order by 1,2,3
/


SHOW INFO BY OBJECTS

SQL> select owner, object_name, object_type, status from all_objects where object_name='TSILGT';

OWNER       OBJECT_NAME       OBJECT_TYPE   STATUS
------------------------------ ------------------------------ ------------------- -------
TREINA       STP_GRAVATABLOG       PROCEDURE   VALID
SANKHYA        STP_GRAVATABLOG       PROCEDURE   VALID
WMS       STP_GRAVATABLOG       PROCEDURE   VALID
TESTE       STP_GRAVATABLOG       PROCEDURE   INVALID

SQL> alter procedure teste.STP_GRAVATABLOG compile;

Warning: Procedure altered with compilation errors.

SQL> show error
Errors for PROCEDURE TESTE.STP_GRAVATABLOG:

LINE/COL ERROR
-------- -----------------------------------------------------------------
33/5 PL/SQL: SQL Statement ignored
46/9 PL/SQL: ORA-00942: table or view does not exist

SQL> SELECT text FROM all_source WHERE name = 'STP_GRAVATABLOG'  and owner='TESTE' ORDER BY line;

SHOW SIZE BY TABLE OR SEGMENTS


SQL>select sum(bytes/1024/1024) as Tamanho_MB from dba_segments
where owner = 'SVP'
and segment_type = 'TABLE'
and segment_name in ('TABLE_1','TABLE_2','TABLE_N')

SQL>select onwer, segment_name, segment_type, tablespace_name, bytes/1024/1024 
from dba_segments where segment_name='TABLE_NAME';

SHOW DATAFILES INFO GENERAL/STATUS 

SQL> select tablespace_name, file_name, bytes/1024/1024 mbytes, AUTOEXTENSIBLE, MAXBYTES/1024/1024 maxbytes, INCREMENT_BY/1024/1024 nextmb from dba_data_files;

TABLESPACE FILE_NAME MBYTES AUT   MAXBYTES   NEXTMB
---------- ---------------------------------------- ---------- --- ---------- ----------
USERS   /u01/app/oracle/oradata/XE/users.dbf    100 YES 11264 .001220703
SYSAUX   /u01/app/oracle/oradata/XE/sysaux.dbf   710 YES 32767.9844 .001220703
UNDOTBS1   /u01/app/oracle/oradata/XE/undotbs1.dbf     75 YES 32767.9844 .000610352
SYSTEM   /u01/app/oracle/oradata/XE/system.dbf   360 YES   600 .001220703


SHOW ALL INX / REBUILD

SQL>select 'alter index ' || owner || '.' || index_name ||' rebuild;'
from dba_indexes
where status ='UNUSABLE'
order by index_name
/



in construction ...