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 / server / Perguntas / 802165
Accepted
dutsnekcirf
dutsnekcirf
Asked: 2016-09-10 09:43:04 +0800 CST2016-09-10 09:43:04 +0800 CST 2016-09-10 09:43:04 +0800 CST

Verificador de versão Pure Perl RPM

  • 772

Tenho uma máquina localizada em um ambiente seguro que não possui acesso à internet. Eu tenho uma carga base do CentOS com um punhado de RPMs adicionais. Isso inclui uma instalação básica do PERL sem módulos adicionais. Também não tem o GCC instalado, então não posso instalar novos módulos manualmente nem usar o CPAN para instalá-los. Portanto, preciso de uma solução Perl pura.

Pediram-me para criar um script Perl que validará se a máquina possui uma lista específica de RPMs instalados e se eles são de uma versão específica ou mais recente.

Aqui está o que eu tenho até agora:

#!/usr/bin/perl

use strict;
use warnings;

# This is the list of RPMs to look for on the machine.
my @RPMs = ("bwm-ng",
        "celt051",
        "device-mapper-multipath",
        "device-mapper-multipath-libs",
        "dhcp",
        "dhcp-common",
        "ebtables",
        "freeglut",
        "glusterfs-api",
        "glusterfs-libs",
        "gnutls-utils",
        "gpm",
        "hmaccalc",
        "iftop",
        "iperf",
        "ipsec-tools",
        "iptraf",
        "iscsi-initiator-utils",
        "libsysfs",
        "lm_sensors",
        "lm_sensors-libs",
        "log4cpp",
        "lrzsz",
        "lzop",
        "mcsctrans",
        "minicom",
        "nc",
        "netcf-libs",
        "net-snmp",
        "net-snmp-libs",
        "net-snmp-utils",
        "omping",
        "perl-AppConfig",
        "perl-Pod-POM",
        "perl-Template-Toolkit",
        "pimd",
        "python-lxml",
        "quagga",
        "radvd",
        "smcroute",
        "usbredir",
        "yajl");

# These are the RPM versions that they should be equal to or newer than.
my @RPMVersions = ("bwm-ng-0.6-6.el6.2.x86_64",
        "celt051-0.5.1.3-0.el6.x86_64",
        "device-mapper-multipath-0.4.9-87.el6.x86_64",
        "device-mapper-multipath-libs-0.4.9-87.el6.x86_64",
        "dhcp-4.1.1-49.P1.el6.centos.x86_64",
        "dhcp-common-4.1.1-49.P1.el6.centos.x86_64",
        "ebtables-2.0.9-6.el6.x86_64",
        "freeglut-2.6.0-1.el6.x86_64",
        "glusterfs-api-3.4.0.57rhs-1.el6_5.x86_64",
        "glusterfs-libs-3.4.0.57rhs-1.el6_5.x86_64",
        "gnutls-utils-2.8.5-18.el6.x86_64",
        "gpm-1.20.6-12.el6.x86_64",
        "hmaccalc-0.9.12-2.el6.x86_64",
        "iftop-1.0-0.7.pre4.el6.x86_64",
        "iperf-2.0.5-11.el6.x86_64",
        "ipsec-tools-0.8.0-25.3.x86_64",
        "iptraf-3.0.1-14.el6.x86_64",
        "iscsi-initiator-utils-6.2.0.873-14.el6.x86_64",
        "libsysfs-2.1.0-7.el6.x86_64",
        "lm_sensors-3.1.1-17.el6.x86_64",
        "lm_sensors-libs-3.1.1-17.el6.x86_64",
        "log4cpp-1.0-13.el6_5.1.x86_64",
        "lrzsz-0.12.20-27.1.el6.x86_64",
        "lzop-1.02-0.9.rc1.el6.x86_64",
        "mcsctrans-0.3.1-4.el6.x86_64",
        "minicom-2.3-6.1.el6.x86_64",
        "nc-1.84-24.el6.x86_64",
        "netcf-libs-0.2.4-3.el6.x86_64",
        "net-snmp-5.5-54.el6.x86_64",
        "net-snmp-libs-5.5-54.el6.x86_64",
        "net-snmp-utils-5.5-54.el6.x86_64",
        "omping-0.0.4-1.el6.x86_64",
        "perl-AppConfig-1.66-6.el6.x86_64",
        "perl-Pod-POM-0.25-2.el6.x86_64",
        "perl-Template-Toolkit-2.22-5.el6.x86_64",
        "pimd-2.3.0-1.x86_64",
        "python-lxml-2.2.3-1.1.el6.x86_64",
        "quagga-0.99.23.1-2014082501.x86_64",
        "radvd-1.6-1.el6.x86_64",
        "smcroute-2.0.0-0.x86_64",
        "usbredir-0.5.1-2.el6.x86_64",
        "yajl-1.0.7-3.el6.x86_64");

my $RPMname; #This reprepsents an individual RPM name within the @RPMs array.

foreach $RPMname (@RPMs){ # Loop through the @RPMs array and query the RPM database for each RPM.
    my $cmd = "rpm -qa | grep " . $RPMname;

    my @cmdResults = `$cmd`;

    if (! @cmdResults){
        print "\tMissing RPM: " . $RPMname . "\n\n"; # If the RPM isn't installed; inform the user.
    } else {
        foreach(@cmdResults){
            print "\t" . $_ . "\n"; # Print the version of the RPM that's currently installed.

            # Compare the RPM version that's installed with the corresponding version that should be installed
            # as listed in the @RPMVersions array.
            # write some magic here. <------

        }
    }
}

exit(0);

Eu encontrei o que parece ser uma solução possível, mas não consigo descobrir como ajustar o código de ajuste ao meu cenário.

veja aqui: http://www.perlmonks.org/bare/?node=240384

Não posso usar o RPM::VersionSort ou vários outros módulos relacionados ao RPM por causa das restrições que mencionei acima.

Qualquer ajuda seria grandemente agradecida.

Obrigado!

scripting perl rpm versioning
  • 2 2 respostas
  • 336 Views

2 respostas

  • Voted
  1. Best Answer
    user9517
    2016-09-10T11:29:01+08:002016-09-10T11:29:01+08:00

    Algumas dicas

    Você não precisa grep por exemplo

    rpm -q radvd
    radvd-1.9.2-9.el7.x86_64
    echo $?
    0
    

    Se um pacote estiver faltando $? é 1

    rpm -q nc 
    package nc is not installed
    echo $?
    1
    

    Você pode obter a versão de um pacote rpm instalado usando --queryformat

    rpm -q radvd --queryformat "%{VERSION}\n"
    1.9.2
    

    Há muito mais que você pode fazer com apenas o rpm— dê uma olhada no site rpm.org .

    Você pode até conseguir escapar sem usar perl, então dê uma olhada na resposta de Dennis aqui no SO .

    • 2
  2. dutsnekcirf
    2016-09-17T08:57:04+08:002016-09-17T08:57:04+08:00

    Embora isso não responda à minha pergunta original, gostaria de fornecer o que acabei. Consegui convencer aqueles que estão no poder a permitir que eu instale o módulo Perl RPM::VersionSort. Portanto, esta não é uma solução Pure Perl como eu esperava encontrar.

    Aqui está o que estou usando agora para quem estiver interessado:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use RPM::VersionSort;
    
    my $cmd;
    my $cmdResults;
    my %installedRPMs; #This will hold a list of all the RPMs from the baseRPMs list that ARE currently installed on the machine.
    my @missingRPMs; #This will hold a list of all the RPMs from the baseRPMs list that ARE NOT installed on the system.
    my %baseRPMs; #This is the list of RPMs that should be installed on the system and their corresponding version numbers.
    
    %baseRPMs = ("bwm-ng" => "0.6-6.el6.2",
            "celt051" => "0.5.1.3-0.el6",
            "device-mapper-multipath" => "0.4.9-87.el6",
            "device-mapper-multipath-libs" => "0.4.9-87.el6",
            "dhcp" => "4.1.1-49.P1.el6.centos",
            "dhcp-common" => "4.1.1-49.P1.el6.centos", 
            "ebtables" => "2.0.9-6.el6",
            "freeglut" => "2.6.0-1.el6",
            "glusterfs-api" => "3.4.0.57rhs-1.el6_5",
            "glusterfs-libs" => "3.4.0.57rhs-1.el6_5",
            "gnutls-utils" => "3.8.5-18.el6",
            "gpm" => "1.20.6-12.el6",
            "hmaccalc" => "0.9.12-2.el6",
            "iftop" => "1.0-0.7.pre4.el6",
            "iperf" => "2.0.5-11.el6",
            "ipsec-tools" => "0.8.0-25.3",
            "iptraf" => "3.0.1-14.el6",
            "iscsi-initiator-utils" => "6.2.0.873-14.el6",
            "libsysfs" => "2.1.0-7.el6",
            "lm_sensors" => "3.1.1-17.el6",
            "lm_sensors-libs" => "3.1.1-17.el6",
            "log4cpp" => "1.0-13.el6_5.1",
            "lrzsz" => "0.12.20-27.1.el6",
            "lzop" => "1.02-0.9.rc1.el6",
            "mcsctrans" => "0.3.1-4.el6",
            "minicom" => "2.3-6.1.el6",
            "nc" => "1.84-24.el6",
            "netcf-libs" => "0.2.4-3.el6",
            "net-snmp" => "5.5-54.el6",
            "net-snmp-libs" => "5.5-54.el6",
            "net-snmp-utils" => "5.5-54.el6",
            "omping" => "0.0.4-1.el6",
            "perl-AppConfig" => "1.66-6.el6",
            "perl-Pod-POM" => "0.25-2.el6",
            "perl-Template-Toolkit" => "2.22-5.el6",
            "pimd" => "2.3.0-1",
            "python-lxml" => "2.2.3-1.1.el6",
            "quagga" => "0.99.23.1-2014082501",
            "radvd" => "1.6-1.el6",
            "smcroute" => "2.0.0-0",
            "usbredir" => "0.5.1-2.el6",
            "yajl" => "1.0.7-3.el6",
        );
    
    print "The following RPMs and version numbers will be checked against this system:\n";
    foreach(keys %baseRPMs){
        print "\t" . $_ . ": " . %baseRPMs($_) . "\n";
    }
    
    print "Press any key to continue.";
    <STDIN>;
    
    #Loop through the %baseRPMs list and build both the %installedRPMs list as well as the @missingRPMs list.
    for my $pkg (keys %baseRPMs){
        $cmd = "rpm -q " . $pkg . " --queryformat \"%{VERSION}-%{RELEASE}\"";
        $cmdResults = `$cmd`;
        if ($cmdResults =~ /not installed/) {
            push @missingRPMs, $pkg;
        } else {
            $installedRPMs{$pkg} = $cmdResults;
        }
    }
    
    #Loop through the %installedRPMs list and verify their version numbers against the %baseRPMs list.
    foreach (keys %installedRPMs){
        if (exists $baseRPMs{$_}){
            print "Expected: " . $_ . ": " . $baseRPMs{$_} .  "\n";
            print "Installed: " . $_ . ": " . $installedRPMs{$_} .  "\n";
            if (rpmvercmp($installedRPMs{$_}, $baseRPMs{$_}) < 0 ) {
                print "RESULT: !!FAIL!! " . $_ . " version is OLDER than the specified version in the Functional Test Plan.\n";
            } else {
                print "RESULT: PASS. " . $_ . " version is equal to or newer than the specified version in the Functional Test Plan. \n";
            }
            print "-----------------------------------------------------------------------------------------------------\n\n";
        }
    }
    
    #Print the list of @missingRPMs.
    if (@missingRPMs){
        print "The following RPMs are NOT installed as defined by the Functional Test Plan:\n";
        foreach(@missingRPMs){
            print "\t" . $_ . "\n";
        }
        print "\n*Any missing RPMs indicates the system is NOT built as defined by the Functional Test Plan.*\n";
    }
    
    print "\n";
    
    exit(0)
    

    ;

    • 0

relate perguntas

Sidebar

Stats

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

    Você pode passar usuário/passar para autenticação básica HTTP em parâmetros de URL?

    • 5 respostas
  • Marko Smith

    Ping uma porta específica

    • 18 respostas
  • Marko Smith

    Verifique se a porta está aberta ou fechada em um servidor Linux?

    • 7 respostas
  • Marko Smith

    Como automatizar o login SSH com senha?

    • 10 respostas
  • Marko Smith

    Como posso dizer ao Git para Windows onde encontrar minha chave RSA privada?

    • 30 respostas
  • Marko Smith

    Qual é o nome de usuário/senha de superusuário padrão para postgres após uma nova instalação?

    • 5 respostas
  • Marko Smith

    Qual porta o SFTP usa?

    • 6 respostas
  • Marko Smith

    Linha de comando para listar usuários em um grupo do Windows Active Directory?

    • 9 respostas
  • Marko Smith

    O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL?

    • 3 respostas
  • Marko Smith

    Como determinar se uma variável bash está vazia?

    • 15 respostas
  • Martin Hope
    Davie Ping uma porta específica 2009-10-09 01:57:50 +0800 CST
  • Martin Hope
    kernel O scp pode copiar diretórios recursivamente? 2011-04-29 20:24:45 +0800 CST
  • Martin Hope
    Robert ssh retorna "Proprietário incorreto ou permissões em ~/.ssh/config" 2011-03-30 10:15:48 +0800 CST
  • Martin Hope
    Eonil Como automatizar o login SSH com senha? 2011-03-02 03:07:12 +0800 CST
  • Martin Hope
    gunwin Como lidar com um servidor comprometido? 2011-01-03 13:31:27 +0800 CST
  • Martin Hope
    Tom Feiner Como posso classificar a saída du -h por tamanho 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent Como determinar se uma variável bash está vazia? 2009-05-13 09:54:48 +0800 CST

Hot tag

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 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