shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script-pt] duvida shell script


From: Marcelo
Subject: Re: [shell-script-pt] duvida shell script
Date: Tue, 13 Jul 2021 13:47:28 -0300

Olá Alfredo,

Havia achado esta solução mesmo,

Muito Obrigado pela resposta...


Att,

Em ter., 13 de jul. de 2021 às 13:10, Alfredo Casanova <atcasanova@gmail.com> escreveu:
Basta usar aspas ao utilizar a variável.


13:09 :) ~ $ output=$(whois -r 243.100.0.0/24)
13:09 :) ~ $ echo $output

% This is the RIPE Database query service. % The objects are in RPSL format. % % The RIPE Database is subject to Terms and Conditions. % See http://www.ripe.net/db/support/db-terms-conditions.pdf % Note: this output has been filtered. % To receive output for a database update, use the "-B" flag. % Information related to '223.27.115.0 - 255.255.255.255' % No abuse contact registered for 223.27.115.0 - 255.255.255.255 inetnum: 223.27.115.0 - 255.255.255.255 netname: NON-RIPE-NCC-MANAGED-ADDRESS-BLOCK descr: IPv4 address block not managed by the RIPE NCC remarks: ------------------------------------------------------ remarks: remarks: For registration information, remarks: you can consult the following sources: remarks: remarks: IANA remarks: http://www.iana.org/assignments/ipv4-address-space remarks: http://www.iana.org/assignments/iana-ipv4-special-registry remarks: http://www.iana.org/assignments/ipv4-recovered-address-space remarks: remarks: AFRINIC (Africa) remarks: http://www.afrinic.net/ whois.afrinic.net remarks: remarks: APNIC (Asia Pacific) remarks: http://www.apnic.net/ whois.apnic.net remarks: remarks: ARIN (Northern America) remarks: http://www.arin.net/ whois.arin.net remarks: remarks: LACNIC (Latin America and the Carribean) remarks: http://www.lacnic.net/ whois.lacnic.net remarks: remarks: ------------------------------------------------------ country: EU # Country is really world wide admin-c: IANA1-RIPE tech-c: IANA1-RIPE status: ALLOCATED UNSPECIFIED mnt-by: RIPE-NCC-HM-MNT created: 2021-03-10T15:02:00Z last-modified: 2021-03-10T15:02:00Z source: RIPE % This query was served by the RIPE Database Query Service version 1.101 (HEREFORD)
13:09 :) ~ $ echo "$output"
% This is the RIPE Database query service.
% The objects are in RPSL format.
%
% The RIPE Database is subject to Terms and Conditions.
% See http://www.ripe.net/db/support/db-terms-conditions.pdf

% Note: this output has been filtered.
%       To receive output for a database update, use the "-B" flag.

% Information related to '223.27.115.0 - 255.255.255.255'

% No abuse contact registered for 223.27.115.0 - 255.255.255.255

inetnum:        223.27.115.0 - 255.255.255.255
netname:        NON-RIPE-NCC-MANAGED-ADDRESS-BLOCK
descr:          IPv4 address block not managed by the RIPE NCC
remarks:        ------------------------------------------------------
remarks:
remarks:        For registration information,
remarks:        you can consult the following sources:
remarks:
remarks:        IANA
remarks:        http://www.iana.org/assignments/ipv4-address-space
remarks:        http://www.iana.org/assignments/iana-ipv4-special-registry
remarks:        http://www.iana.org/assignments/ipv4-recovered-address-space
remarks:
remarks:        AFRINIC (Africa)
remarks:        http://www.afrinic.net/ whois.afrinic.net
remarks:
remarks:        APNIC (Asia Pacific)
remarks:        http://www.apnic.net/ whois.apnic.net
remarks:
remarks:        ARIN (Northern America)
remarks:        http://www.arin.net/ whois.arin.net
remarks:
remarks:        LACNIC (Latin America and the Carribean)
remarks:        http://www.lacnic.net/ whois.lacnic.net
remarks:
remarks:        ------------------------------------------------------
country:        EU # Country is really world wide
admin-c:        IANA1-RIPE
tech-c:         IANA1-RIPE
status:         ALLOCATED UNSPECIFIED
mnt-by:         RIPE-NCC-HM-MNT
created:        2021-03-10T15:02:00Z
last-modified:  2021-03-10T15:02:00Z
source:         RIPE

% This query was served by the RIPE Database Query Service version 1.101 (HEREFORD)

On Tue, Jul 13, 2021 at 11:26 AM Marcelo <msalavee@gmail.com> wrote:
Olá Marcelo,

Obrigado pela dica, mas estou com problema pq a variável do whois retorna em uma linha só...

resultado do whois:

% This is the RIPE Database query service. % The objects are in RPSL format. % % The RIPE Database is subject to Terms and Conditions. % See http://www.ripe.net/db/support/db-terms-conditions.pdf % Note: this output has been filtered. % To receive output for a database update, use the "-B" flag. % Information related to '243.100.0.0 - 243.110.95.255' % No abuse contact registered for 243.100.0.0 - 243.110.95.255 inetnum: 243.100.0.0 - 243.110.95.255 netname: NON-RIPE-NCC-MANAGED-ADDRESS-BLOCK descr: IPv4 address block not managed by the RIPE NCC remarks: ------------------------------------------------------ remarks: remarks: For registration information, remarks: you can consult the following sources: remarks: remarks: IANA remarks: http://www.iana.org/assignments/ipv4-address-space remarks: http://www.iana.org/assignments/iana-ipv4-special-registry remarks: http://www.iana.org/assignments/ipv4-recovered-address-space remarks: remarks: AFRINIC (Africa) remarks: http://www.afrinic.net/ whois.afrinic.net remarks: remarks: APNIC (Asia Pacific) remarks: http://www.apnic.net/ whois.apnic.net remarks: remarks: ARIN (Northern America) remarks: http://www.arin.net/ whois.arin.net remarks: remarks: LACNIC (Latin America and the Carribean) remarks: http://www.lacnic.net/ whois.lacnic.net remarks: remarks: ------------------------------------------------------ country: EU # Country is really world wide admin-c: IANA1-RIPE tech-c: IANA1-RIPE status: ALLOCATED UNSPECIFIED mnt-by: RIPE-NCC-HM-MNT created: 2020-02-10T11:31:57Z last-modified: 2020-02-10T11:31:57Z source: RIPE % This query was served by the RIPE Database Query Service version 1.101 (HEREFORD)

E deveria ser assim:

% This is the RIPE Database query service.
% The objects are in RPSL format.
%
% The RIPE Database is subject to Terms and Conditions.
% See http://www.ripe.net/db/support/db-terms-conditions.pdf

% Note: this output has been filtered.
%       To receive output for a database update, use the "-B" flag.

% Information related to '243.100.0.0 - 243.110.95.255'

% No abuse contact registered for 243.100.0.0 - 243.110.95.255

inetnum:        243.100.0.0 - 243.110.95.255
netname:        NON-RIPE-NCC-MANAGED-ADDRESS-BLOCK
descr:          IPv4 address block not managed by the RIPE NCC
remarks:        ------------------------------------------------------
remarks:
remarks:        For registration information,
remarks:        you can consult the following sources:
remarks:
remarks:        IANA
remarks:        http://www.iana.org/assignments/ipv4-address-space
remarks:        http://www.iana.org/assignments/iana-ipv4-special-registry
remarks:        http://www.iana.org/assignments/ipv4-recovered-address-space
remarks:
remarks:        AFRINIC (Africa)
remarks:        http://www.afrinic.net/ whois.afrinic.net
remarks:
remarks:        APNIC (Asia Pacific)
remarks:        http://www.apnic.net/ whois.apnic.net
remarks:
remarks:        ARIN (Northern America)
remarks:        http://www.arin.net/ whois.arin.net
remarks:
remarks:        LACNIC (Latin America and the Carribean)
remarks:        http://www.lacnic.net/ whois.lacnic.net
remarks:
remarks:        ------------------------------------------------------
country:        EU # Country is really world wide
admin-c:        IANA1-RIPE
tech-c:         IANA1-RIPE
status:         ALLOCATED UNSPECIFIED
mnt-by:         RIPE-NCC-HM-MNT
created:        2020-02-10T11:31:57Z
last-modified:  2020-02-10T11:31:57Z
source:         RIPE

% This query was served by the RIPE Database Query Service version 1.101 (ANGUS)



Em ter., 13 de jul. de 2021 às 09:24, Marcelo Primo por (shell-script-pt) <shell-script-pt@nongnu.org> escreveu:

Bom dia Xará,

Para minimizar a quantidade de vezes que você executa o whois, você pode executar o comando e atribuí-lo a uma variável. Por exemplo:

saida_whois=$(whois $IP)

Depois para trabalhar o conteúdo, você pode fazer os grep(s), sed(s) e awk(s) que desejar. Outro exemplo:

grep "route" <<< "$saida_whois"

e por aí vai.

Espero ter ajudado.

Atenciosamente,

Marcelo


Em 13/07/2021 08:06, Marcelo escreveu:
Bom dia,

Quero fazer um script que faz um whois em um ip e pega separado alguns valores como abaixo:


WHOISROUTE=`whois -r $IP |fgrep -i "route:" | uniq | head -1 | awk  '{print $2}'`

WHOISCIDR=`whois -r $IP |fgrep -i "cidr: " | uniq | head -1 | awk  '{print $2 $3}'`

WHOISINETNUM=`whois -r $IP |fgrep -i "inetnum" | uniq  | head -1 | awk  '{print $2 $3 $4}'`

Só que para cada valor obtido destas variáveis eu tenho que rodar novamente o whois, como eu faria para rodar somente uma vez o whois e pegar todos os valores?


Obrigado!

_______________________________________________
Lista brasileira de usuários de shell script
Endereço de e-mail da lista: shell-script-pt@nongnu.org
Para se inscrever ou desinscrever acesse: https://lists.nongnu.org/mailman/listinfo/shell-script-pt
Para ver os arquivos da lista (mensagens anteriores) e pesquisar nelas, acesse https://lists.nongnu.org/archive/html/shell-script-pt/

NOTA: A lista anterior, no Yahoo Groups, foi *desativada*. Por favor utilize somente esta.
_______________________________________________
Lista brasileira de usuários de shell script
Endereço de e-mail da lista: shell-script-pt@nongnu.org
Para se inscrever ou desinscrever acesse: https://lists.nongnu.org/mailman/listinfo/shell-script-pt
Para ver os arquivos da lista (mensagens anteriores) e pesquisar nelas, acesse https://lists.nongnu.org/archive/html/shell-script-pt/

NOTA: A lista anterior, no Yahoo Groups, foi *desativada*. Por favor utilize somente esta.
_______________________________________________
Lista brasileira de usuários de shell script
Endereço de e-mail da lista: shell-script-pt@nongnu.org
Para se inscrever ou desinscrever acesse: https://lists.nongnu.org/mailman/listinfo/shell-script-pt
Para ver os arquivos da lista (mensagens anteriores) e pesquisar nelas, acesse https://lists.nongnu.org/archive/html/shell-script-pt/

NOTA: A lista anterior, no Yahoo Groups, foi *desativada*. Por favor utilize somente esta.


--
[]'s
Alfredo Tristão Casanova
Linux User #228230

_______________________________________________
Lista brasileira de usuários de shell script
Endereço de e-mail da lista: shell-script-pt@nongnu.org
Para se inscrever ou desinscrever acesse: https://lists.nongnu.org/mailman/listinfo/shell-script-pt
Para ver os arquivos da lista (mensagens anteriores) e pesquisar nelas, acesse https://lists.nongnu.org/archive/html/shell-script-pt/

NOTA: A lista anterior, no Yahoo Groups, foi *desativada*. Por favor utilize somente esta.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]