AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / unix / Perguntas / 793338
Accepted
user447274
user447274
Asked: 2025-04-05 05:38:33 +0800 CST2025-04-05 05:38:33 +0800 CST 2025-04-05 05:38:33 +0800 CST

Listar e contar cifras usadas pelo cryptsetup em dispositivos /dev/mapper

  • 772

No meu computador Linux tenho /dev/mapper/muitos arquivos chamados file1, file2, file3.... .

Agora terei uma visão geral dos arquivos sobre qual cifra é usada com que frequência.

Eu tentei isso

for i in /dev/mapper/file* ; do cryptsetup status $i | grep cipher ; done | sort

e se tornar esta saída

  cipher:  aes-cbc-essiv:sha256
  cipher:  aes-cbc-essiv:sha256
  cipher:  aes-cbc-essiv:sha256
  cipher:  aes-cbc-essiv:sha256
  cipher:  aes-cbc-essiv:sha256
  cipher:  aes-cbc-essiv:sha256
  cipher:  aes-cbc-essiv:sha256
  cipher:  aes-cbc-essiv:sha256
  cipher:  aes-cbc-essiv:sha256
  cipher:  aes-cbc-essiv:sha256
  cipher:  aes-cbc-essiv:sha256
  cipher:  aes-cbc-essiv:sha256
  cipher:  aes-cbc-essiv:sha256
  cipher:  aes-xts-plain64
  cipher:  aes-xts-plain64
  cipher:  aes-xts-plain64
  cipher:  serpent-xts-plain64
  cipher:  serpent-xts-plain64

mas estou procurando uma saída como esta:

13x  cipher:  aes-cbc-essiv:sha256
 3x  cipher:  aes-xts-plain64
 2x  cipher:  serpent-xts-plain64

e adicionalmente uma saída como esta:

file1  use cipher aes-xts-plain64
file2  use cipher serpent-xts-plain64
....
file13 use cipher aes-xts-plain64
linux
  • 2 2 respostas
  • 75 Views

2 respostas

  • Voted
  1. Best Answer
    Hauke Laging
    2025-04-05T06:49:59+08:002025-04-05T06:49:59+08:00

    Em bash:

    #!/usr/bin/env bash
    
    declare -A cipher
    for file in /dev/mapper/file* ; do
        output="$( cryptsetup status "$file" | awk '$1=="cipher:" { print $2; }' )"
        test -n "$output" && cipher["$file"]="$output"
    done
    
    printf '%s\n' "${cipher[@]}" | sort -n | uniq -c
    
    for file in "${!cipher[@]}"; do
        echo "${file#/dev/mapper/}: ${cipher["$file"]}"
    done | column -t
    
    • 2
  2. markp-fuso
    2025-04-05T12:16:07+08:002025-04-05T12:16:07+08:00

    Não trabalho com, cryptsetupentão criarei os seguintes arquivos para simular a saída de cryptsetup:

    i=1
    for c in 'aes-cbc-essiv:sha256' 'aes-xts-plain64' 'serpent-xts-plain64'
    do
        for ((j=i;j<=12;j+=3))
        do
            echo "  cipher: $c" > "file$j"
        done
        ((i++))
    done
    

    Para simular a corrida, cryptsetup status $iexecutarei cat $i, por exemplo:

    $ cat file1
      cipher: aes-cbc-essiv:sha256
    
    $ cat file2
      cipher: aes-xts-plain64
    

    Como não estou familiarizado com cryptsetupa saída, vou findimprimir o nome do arquivo e então chamar cat:

    $ find . -name 'file*' -printf "FILE: %f\n" -exec cat {} \;
    FILE: file2
      cipher: aes-xts-plain64
    FILE: file8
      cipher: aes-xts-plain64
    FILE: file12
      cipher: serpent-xts-plain64
    ... snip ...
    

    Agora posso alimentar isso para awksomar contagens, imprimir as file use cipherlinhas em cipher_list.txte, finalmente, imprimir as contagens totais em cipher_counts.txt:

    awk  '
    $1 == "FILE:"   { fname = $2; next }
    $1 == "cipher:" { counts[$2]++
                      printf "%s use cipher %s\n", fname, $2 > "cipher_list.txt"
                    }
    END             { for (cipher in counts)
                          printf "%sx cipher: %s\n", counts[cipher], cipher > "cipher_counts.txt"
                    }
    ' < <(find . -name 'file*' -printf "FILE: %f\n" -exec cat {} \; )
    

    Os resultados:

    $ cat cipher_counts.txt
    4x cipher: aes-xts-plain64
    4x cipher: serpent-xts-plain64
    4x cipher: aes-cbc-essiv:sha256
    
    $ cat cipher_list.txt
    file2 use cipher aes-xts-plain64
    file8 use cipher aes-xts-plain64
    file12 use cipher serpent-xts-plain64
    file11 use cipher aes-xts-plain64
    file6 use cipher serpent-xts-plain64
    file5 use cipher aes-xts-plain64
    file3 use cipher serpent-xts-plain64
    file10 use cipher aes-cbc-essiv:sha256
    file9 use cipher serpent-xts-plain64
    file7 use cipher aes-cbc-essiv:sha256
    file1 use cipher aes-cbc-essiv:sha256
    file4 use cipher aes-cbc-essiv:sha256
    

    A partir daqui, o OP pode executar os arquivos sorte columnformatá-los conforme desejado. Poderíamos empurrar a classificação e a formatação de impressão final para cima no awkcódigo, mas eu queria manter o awkcódigo (relativamente) simples neste ponto.

    Por exemplo, classificando cipher_list.txtpor nome de arquivo (e assumindo apenas uma linha/cifra por arquivo) e espaçando as colunas com no mínimo 1 espaço:

    $ sort -V cipher_list.txt | column -t -o ' '
    file1  use cipher aes-cbc-essiv:sha256
    file2  use cipher aes-xts-plain64
    file3  use cipher serpent-xts-plain64
    file4  use cipher aes-cbc-essiv:sha256
    file5  use cipher aes-xts-plain64
    file6  use cipher serpent-xts-plain64
    file7  use cipher aes-cbc-essiv:sha256
    file8  use cipher aes-xts-plain64
    file9  use cipher serpent-xts-plain64
    file10 use cipher aes-cbc-essiv:sha256
    file11 use cipher aes-xts-plain64
    file12 use cipher serpent-xts-plain64
    

    Quanto ao ambiente real do OP, presumo que seria suficiente para ele fazer a seguinte alteração:

    ##### change this:
    
    ' < <(find . -name 'file*' -printf "FILE: %f\n" -exec cat {} \; )
                                                          ^^^^^^
    
    ##### to this:
    
    ' < <(find . -name 'file*' -printf "FILE: %f\n" -exec cryptsetup status {} \; )
                                                          ^^^^^^^^^^^^^^^^^^^^
    
    • 2

relate perguntas

  • Existe uma maneira de fazer ls mostrar arquivos ocultos apenas para determinados diretórios?

  • Inicie/pare o serviço systemd usando o atalho de teclado [fechado]

  • Necessidade de algumas chamadas de sistema

  • astyle não altera a formatação do arquivo de origem

  • Passe o sistema de arquivos raiz por rótulo para o kernel do Linux

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Possível firmware ausente /lib/firmware/i915/* para o módulo i915

    • 3 respostas
  • Marko Smith

    Falha ao buscar o repositório de backports jessie

    • 4 respostas
  • Marko Smith

    Como exportar uma chave privada GPG e uma chave pública para um arquivo

    • 4 respostas
  • Marko Smith

    Como podemos executar um comando armazenado em uma variável?

    • 5 respostas
  • Marko Smith

    Como configurar o systemd-resolved e o systemd-networkd para usar o servidor DNS local para resolver domínios locais e o servidor DNS remoto para domínios remotos?

    • 3 respostas
  • Marko Smith

    apt-get update error no Kali Linux após a atualização do dist [duplicado]

    • 2 respostas
  • Marko Smith

    Como ver as últimas linhas x do log de serviço systemctl

    • 5 respostas
  • Marko Smith

    Nano - pule para o final do arquivo

    • 8 respostas
  • Marko Smith

    erro grub: você precisa carregar o kernel primeiro

    • 4 respostas
  • Marko Smith

    Como baixar o pacote não instalá-lo com o comando apt-get?

    • 7 respostas
  • Martin Hope
    user12345 Falha ao buscar o repositório de backports jessie 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl Por que a maioria dos exemplos do systemd contém WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky Como exportar uma chave privada GPG e uma chave pública para um arquivo 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll status systemctl mostra: "Estado: degradado" 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim Como podemos executar um comando armazenado em uma variável? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S Por que /dev/null é um arquivo? Por que sua função não é implementada como um programa simples? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 Como ver as últimas linhas x do log de serviço systemctl 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - pule para o final do arquivo 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla Por que verdadeiro e falso são tão grandes? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis Substitua a string em um arquivo de texto enorme (70 GB), uma linha 2017-12-30 06:58:33 +0800 CST

Hot tag

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve