VÁRIOS SCRIPTS EM SHELL E DICAS DE COMANDOS DE LINUX

CONTAR O NUMERO DE PROCESSOS

ps aux |wc -l

CONTAR NUMERO DE PROCESSOS

ps -ef |wc -l

Apaga todos os aquivos di dia 30 de Maio

 for i in `ls -ltr |grep 'May 30'|awk '{print $9}'`
 do
 rm -fr $i
 echo $i
 done
 ----move todos os arquivo do dia 23 de outubro para a pasta old
for i in `ls -ltr |grep 'Oct 23'|awk '{print $9}'`
 do
 mv $i to old/
 echo $i
 done
 ---- apaga todos os aquivos do mes de junho
for i in `ls -ltr |grep 'Jun '|awk '{print $9}'`
 do
 rm -fr $i
 echo $i
 done

 Mostra todos os arquivos maiores que 1000000
 ------------------------------------------
for i in `du -k |awk '{print $1}'`
 do
 if [ "$i" -gt 1000000 ]
 then
 echo $i
 fi
 done

——————————————

> ls -ltr |grep 'Jul 16'|awk '{print $9}'
-------------------------------------------------------------------
 deleta por DIA
-------------------------------------------------------------------
for linha in `ls -ltr |grep 'Sep 25' |awk '{print $9}'`
 do
 rm $linha
 echo 'DELETEI O ARQUIVO ' $linha
 done
-------------------------------------------------------------------
 deleta por MES
-------------------------------------------------------------------
for linha in `ls -ltr |grep 'Aug' |awk '{print $9}'`
 do
 rm $linha
 echo $linha
 done
for linha in `ls -ltr |grep 'Aug 14' |awk '{print $9}'`
 do
 rm $linha
 echo $linha
 done
du -k |awk '{print $1}'| sort -u
du -k |awk '{print $1}'| sort -A
-------------------------------------------------------------------

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

AWK COM IF MUDANDO COR DA TELA *-*-*-/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

 awk '
 { if ($6 >=550 && $6 <2000){system("tput bel ~/");system("tput blink ~/");system("tput setaf 1 ~/");system("tput bold ~/"); print "| INSTANCIA 1 = > " $6 , " INSTANCIA 2 = > " $11, " INSTANCIA 3 = > " $16," |";}
 else if ($11>=550 && $11<2000){system("tput bel ~/");system("tput blink ~/");system("tput setaf 1 ~/");system("tput bold ~/"); print "| INSTANCIA 1 = > " $6 , " INSTANCIA 2 = > " $11, " INSTANCIA 3 = > " $16," |";}
 else if ($16>=550 && $16<2000){system("tput bel ~/");system("tput blink ~/");system("tput setaf 1 ~/");system("tput bold ~/"); print "| INSTANCIA 1 = > " $6 , " INSTANCIA 2 = > " $11, " INSTANCIA 3 = > " $16," |";}
 else if ($6 <550 && $6>=400) {system("tput sgr0 ~/");system("tput setaf 3 ~/");system("tput bold ~/"); print "| INSTANCIA 1 = > " $6 , " INSTANCIA 2 = > " $11, " INSTANCIA 3 = > " $16," |";}
 else if ($11<550 && $11>=400){system("tput sgr0 ~/");system("tput setaf 3 ~/");system("tput bold ~/"); print "| INSTANCIA 1 = > " $6 , " INSTANCIA 2 = > " $11, " INSTANCIA 3 = > " $16," |";}
 else if ($16<550 && $16>=400){system("tput sgr0 ~/");system("tput setaf 3 ~/");system("tput bold ~/"); print "| INSTANCIA 1 = > " $6 , " INSTANCIA 2 = > " $11, " INSTANCIA 3 = > " $16," |";}
 else if ($6 >=0 && $6 <=400){system("tput sgr0 ~/");system("tput setaf 2 ~/");system("tput bold ~/"); print "| INSTANCIA 1 = > " $6 , " INSTANCIA 2 = > " $11, " INSTANCIA 3 = > " $16," |";}
 else if ($11>=0 && $11<=400){system("tput sgr0 ~/");system("tput setaf 2 ~/");system("tput bold ~/"); print "| INSTANCIA 1 = > " $6 , " INSTANCIA 2 = > " $11, " INSTANCIA 3 = > " $16," |";}
 else if ($16>=0 && $16<=400){system("tput sgr0 ~/");system("tput setaf 2 ~/");system("tput bold ~/"); print "| INSTANCIA 1 = > " $6 , " INSTANCIA 2 = > " $11, " INSTANCIA 3 = > " $16," |";}
 else if ($2 == "-----------------------------------------------------------------" ) {system("tput sgr0 ~/");system("tput setaf 2 ~/"); print $0;}
 else if ($10 >=450 && $10 <1000) {system("tput bel ~/");system("tput blink ~/"); system("tput setaf 1 ~/");system("tput bold ~/"); print $0;}
 else if ($10 >=300 && $10 <450) {system("tput sgr0 ~/");system("tput setaf 3 ~/");system("tput bold ~/"); print $0;}
 else if ($6 == "|" ) {system("tput sgr0 ~/");system("tput setaf 2 ~/");system("tput bold ~/"); print $0;}
 else if ($6 == "L" ) {system("tput sgr0 ~/");system("tput setaf 7 ~/");system("tput bold ~/"); print $0;}
 else if ($6 == "INST" ) {system("tput sgr0 ~/");system("tput setaf 7 ~/");system("tput bold ~/"); print $0;}
 else if ($6 == "ORACLE" ) {system("tput sgr0 ~/");system("tput setaf 2 ~/");system("tput bold ~/"); print $0;}
 else null;
 }' /u01/app/operacao/scr/novoconexoes_tst.txt

*-*-*-/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

NAWK COM IF

*-*-*-/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

 while read i
 do
 pctot=`echo $i | nawk '{printf ("%d\n", $7 * 10)}'`
 if (($pctot == 0));then
 tput setaf 2
 echo "$i"
 elif (($pctot < 50)); then
 tput setaf 3
 echo "$i"
 else
 tput setaf 1
 echo "$i"
 fi
 done < srs_ale.txt
para mudar de cor
 tput setaf 1
para tocar beep
 tput bel
para começar a piscar
 tput blink
para parar de piscar
 tput sgr0
echo "`tput blink` `tput setaf 1 `hightlighted`tput sgr0`"
 system("tput bold ~/");
----------------------------------------------

####numero das linhas
 cat -n alert_ALEXDB1.log|grep "ORA-"

Mostra texto de linas entre 2 numeros de linha

sed -n 191391,191399p alert_ALEXDB1.log

Acha e mostra todos as linhas com o texto “ORA-”

 grep -c "ORA-" /DADOS/FULL/log/logbkp.${DATABKP}.log

Acha e mostra as linhas com o texto “ORA-” das 500 ultimas linhas

tail -500 /oracle/product/app/admin/ALEXDB/bdump/alert_ALEXDB1.log |grep -c "ORA-"
cat -n|tail -50 /oracle/product/app/admin/ALEXDB/bdump/alert_ALEXDB1.log |grep "ORA-"
cat -n /oracle/product/app/admin/ALEXDB/bdump/alert_ALEXDB1.log |grep "ORA-"| tail -50
awk '$5>=95 && $5<101 {system("tput setaf 1 ~/"); print $0;}
 $5<95 && $5>31 {system("tput setaf 3 ~/"); print $0;}
 $5>0 && $5<=30 {system("tput setaf 2 ~/"); print $0;}
 $7 *10 >=300 && $7 *10 <1100 {system("tput setaf 1 ~/"); print $0;}
 $7 *10 >=0 && $7 *10 <= 9 {system("tput setaf 2 ~/"); print $0;}
 $7 *10 >=10 && $7 *10 <=299 {system("tput setaf 3 ~/"); print $0;}' srs_mon.txt
for i in `cat -n /oracle/product/app/admin/ALEXDB/bdump/alert_ALEXDB1.log |grep "ORA-"| tail -5|awk '{print $1}'`
 do
 if [ $i -eq 0 ];
 then
 echo "NÃO TEM ERROS";
 else
 #echo $i "eq nao zero ";
 sed -n $i,$(i +2)\p /oracle/product/app/admin/ALEXDB/bdump/alert_ALEXDB1.log >> /DADOS/FULL/log/errosALEXDB1.log
 mailx -s "ERROS NO ALERT DA PRODUÇÂO ALEXDB1" dba@pires.com.br < //DADOS/FULL/log/errosALEXDB1.log
 fi;
 done

*-*-*-/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

for i in `cat -n /oracle/product/app/admin/ALEXDB/bdump/alert_ALEXDB1.log |grep "ORA-"| tail -2500|awk '{print $1}'`
 do
 if [ $i -eq 0 ];
 then
 echo "NÃO TEM ERROS";
 else
 #echo $i "eq nao zero ";
 sed -n $i,$(($i +2))\p /oracle/product/app/admin/ALEXDB/bdump/alert_ALEXDB1.log >> /DADOS/FULL/log/errosALEXDB1.log
 fi;
 done
 if [ -f $filename ];
 then
 mailx -s "ERROS NO ALERT DA PRODUÇÂO ALEXDB1" dba@pires.com.br < /DADOS/FULL/log/errosALEXDB1.log
 rm /DADOS/FULL/log/errosALEXDB1.log
 fi;

*-*-*-/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

awk cat -n /oracle/product/app/admin/ALEXDB/bdump/alert_ALEXDB1.log |grep "ORA-"| tail -50

 sed -n 192369,(192369+3)P alert_ALEXDB1.log

/oracle/product/app/admin/ALEXDB/bdump/alert_ALEXDB1.log

cat -n /oracle/product/app/admin/ALEXDB/bdump/alert_ALEXDB1.log |grep "ORA-"| tail -50

Programa para enviar -email quando achar erros nos alert do banco

tail -500 /oracle/product/app/admin/ALEXDB/bdump/alert_ALEXDB1.log |grep -c "ORA-"

 if [ $? -eq 0 ] ## ERRO NO ALERT
 then
 ##echo "ACHOU ERRO NO ALERT"
 grep "ORA-" /oracle/product/app/admin/ALEXDB/bdump/alert_ALEXDB1.log >> /DADOS/FULL/log/ERROBKP.${DATABKP}.log
 mailx -s "ERROS NO ALERT DA PRODUÇÂO ALEXDB1" dba@pires.com.br < /DADOS/FULL/log/ERROBKP.${DATABKP}.log
 mailx -s "Fim Backup FULL Oracle COM ERRO - Producao - IBM" dba@pires.com.br < /DADOS/FULL/log/logbkp.${DATABKP}.log
 else
 ##echo "BACKUP FEITO COM SUCESSO"
 mailx -s "Fim Backup FULL Oracle com sucesso - Producao" dba@pires.com.br,operacao@pires.com.br,sysadm@pires.com.br < /DADOS/FULL/log/logbkp.${DATABKP}.log
 fi

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
COPIA ARCHIVES
/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

 #!/usr/bin/bash
 ls /ARCHIVE/*.arc | awk -F"/" '{print $3}' > /tmp/local1.tmp
 ssh oracle@apolo "ls /backup/arch/SPCAP/*.arc" | awk -F"/" '{print $5}' > /tmp/local2.tmp
 diff /tmp/local1.tmp /tmp/local2.tmp | grep "<" | awk '{print "scp -c blowfish -C /ARCHIVE/" $2 " oracle@apolo:/backup/arch/SPCAP/."
 }' | bash

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
Comando pra saber se uma maquina linux é vmware ou virtual
/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

lspci

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
COMANDOS DE DISCO UTIL COM ASM
/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
verifica discos

lsdev -Ccdisk

Verificar conteudo do disco

lspv | grep hdisk7
lquerypv -h /dev/rhdiskpower33

discos com problema
25 CANDIDATE NORMAL /dev/rhdiskpower33
27 CANDIDATE NORMAL /dev/rhdiskpower35

chdev -l /dev/rhdiskpower33 -a reserve_lock=no
chdev -l /dev/rhdiskpower35 -a reserve_lock=no
chdev -l hdiskpower35 -a reserve_lock=no
hdiskpower35 changed

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

MUDANDO NOME DO HOST NO LINUX

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

Tenta mudar no arquivo /etc/hosts
x.x.x.x meu.dominio.com.br hostname
e muda tb la no /etc/sysconfig/network
HOSTNAME: nome

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

COMANDO DE MOUNT DE NFS
/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

mount -o fastattr,hard,rw,noac,proto=udp,bg,intr,retrans=10,timeo=1000,vers=3 10.198.35.11:/backup /DADOS

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

COMANDO DE CRIAÇÃO DE LINK SIMBÓLICO

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

create a symbolic link "ln -s /usr/lib/libgdbm.so.2.0.0 /usr/lib/libdb.so.2"
ln -s /usr/lib64/libdb1.so.2 /usr/lib/libdb.so.2
ln -s /usr/lib64/libgdbm.so.2.0.0 /usr/lib64/libdb.so.2

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

Solution
Enhancement Request ( Unpublished Bug 8303425 ) has this issue discussed.

1] If creating new ASMLib Devices, give label name with no more than 24 characters.

2] When you see ORA-15040, ORA-15042, then you can do the followings:

shutdown ASM instances on All the nodes

take 50 MB ‘dd’ backup of All the disks in the affected diskgroup

dd if=/dev/emcpoweral1 of=/tmp/al1.50m.dd bs=1024 count=51200

==============================================================:

IMPORTANT: This is a must safety measure, in case anything happens in the next step, we can go back to the original state. Also it is recommended that you open an SR with Oracle GCS.

use force-renamedisk commad to change ” driver.provstr ” value and provide a label length <= 24. This needs to be done for all the affected disks.

/etc/init.d/oracleasm force-renamedisk /dev/emcpoweral1 P300R10RG2D13

Run the scandisks command on All the nodes

/etc/init.d/oracleasm scandisks
 Check the disks are visible on All the nodes, with new labels

Sobre Alexandre Pires

ORACLE OCS Goldengate Specialist, OCE RAC 10g R2, OCP 12C, 11g, 10g , 9i e 8i - Mais de 25 anos de experiência na área de TI. Participei de projetos na G&P alocado na TOK STOK, EDINFOR alocado na TV CIDADE "NET", 3CON Alocado no PÃO DE AÇUCAR, DISCOVER alocado na VIVO, BANCO IBI e TIVIT, SPC BRASIL, UOLDIVEO alocado no CARREFOUR e atualmente na ORACLE ACS atendendo os seguintes projetos: VIVO, CLARO, TIM, CIELO, CAIXA SEGUROS, MAPFRE, PORTO SEGURO, SULAMERICA, BRADESCO SEGUROS, BANCO BRADESCO, BASA, SANTANDER, CNJ, TSE, ELETROPAULO, EDP, SKY, NATURA, ODEBRESHT, NISSEI, SICREDI, CELEPAR, TAM, TIVIT, IBM, SMILES, CELEPAR, SERPRO,OKI,BANCO PAN, etc
Esse post foi publicado em SHELL SCRIPT, TUTORIAL e marcado , , , , , , , , , , , , , , , , , , , , , , , , , . Guardar link permanente.

Deixe uma resposta

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s