Affichage des articles dont le libellé est cli. Afficher tous les articles
Affichage des articles dont le libellé est cli. Afficher tous les articles

31 mars 2016

[CENTOS / RHEL] Trouver le package lié à une commande avec yum

Il arrive que l'on cherche à utiliser une commande. Dans mon cas, il s'agit de la commande xml_split.

Cependant, quand on cherche xml_split avec yum search:

# yum search xml_split
Modules complémentaires chargés : fastestmirror
base                                                                                                   | 3.6 kB  00:00:00
epel/x86_64/metalink                                                                                   |  26 kB  00:00:00
epel                                                                                                   | 4.3 kB  00:00:00
extras                                                                                                 | 3.4 kB  00:00:00
updates                                                                                                | 3.4 kB  00:00:00
vmware-tools                                                                                           |  951 B  00:00:00
(1/7): base/7/x86_64/group_gz                                                                          | 155 kB  00:00:00
(2/7): epel/x86_64/group_gz                                                                            | 169 kB  00:00:00
(3/7): extras/7/x86_64/primary_db                                                                      | 101 kB  00:00:00
(4/7): epel/x86_64/updateinfo                                                                          | 525 kB  00:00:00
(5/7): epel/x86_64/primary_db                                                                          | 4.0 MB  00:00:00
(6/7): updates/7/x86_64/primary_db                                                                     | 3.2 MB  00:00:00
(7/7): base/7/x86_64/primary_db                                                                        | 5.3 MB  00:00:01
vmware-tools/primary                                                                                   | 1.0 kB  00:00:00
Determining fastest mirrors
 * base: centos.crazyfrogs.org
 * epel: epel.besthosting.ua
 * extras: centos.mirror.fr.planethoster.net
 * updates: centos.mirror.fr.planethoster.net
vmware-tools                                                                                                              2/2
Attention : aucune correspondance trouvée pour : xml_split
No matches found
Mauvaise nouvelle, aucun package ne porte ce nom et donc, nous n'obtenons aucun résultat ...

Heureusement il y a une solution avec yum provides:

# yum provides */xml_split
Modules complémentaires chargés : fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.crazyfrogs.org
 * epel: epel.besthosting.ua
 * extras: centos.mirror.fr.planethoster.net
 * updates: centos.mirror.fr.planethoster.net
base/7/x86_64/filelists_db                                                                             | 6.2 MB  00:00:01
epel/x86_64/filelists_db                                                                               | 6.5 MB  00:00:01
extras/7/x86_64/filelists_db                                                                           | 258 kB  00:00:00
updates/7/x86_64/filelists_db                                                                          | 2.1 MB  00:00:00
vmware-tools/filelists                                                                                 |  433 B  00:00:00
openvas-manager-6.0.3-3.el7.x86_64 : Manager Module for the Open Vulnerability Assessment System (OpenVAS)
Dépôt               : epel
Correspondance depuis :
Nom de fichier : /usr/share/openvas/scap/xml_split



perl-XML-Twig-3.44-2.el7.noarch : Perl module for processing huge XML documents in tree mode
Dépôt               : base
Correspondance depuis :
Nom de fichier : /usr/bin/xml_split
Et voilà, ici on se rend compte que la commande xml_split est contenue dans perl-XML-Twig-3.44-2.el7.noarch

24 févr. 2016

[UNIX/LINUX] Encoder un fichier en UTF-8

J'ai eu récemment le cas d'un document récupéré sur une machine windows dont certains caractères n'étaient pas visibles: notamment les s'affichaient <80> dans vim.

Déjà, pour connaitre l'encodage d'un fichier:
Sous Ubuntu
$ uchardet fichier.txt
windows-1252
Sous CentOS (et aussi Ubuntu)
$ file -i fichier.txt
fichier.txt: text/html; charset=unknown-8bit
Je n'ai pas trouvé d'équivalence de uchardet dans CentOS...

Maintenant, comment encoder le fameux fichier windows-1252 en UTF-8 (avec iconv disponible sur CentOS et Ubuntu):
$ iconv -f windows-1252 -t UTF-8 fichier.txt -o fichier-utf8.txt
et voilà :
$ file -i fichier-utf8.txt
fichier-utf8.txt: application/xml; charset=utf-8
Il va de soi que l'on peut utiliser iconv pour convertir dans les deux sens, ou depuis un autre format
exemple:
$ iconv -f UTF-8 -t ISO-8859-1 fichier.txt -o fichier-utf8.txt

17 févr. 2016

[JSON] Comment parser du JSON via Linux (EN)

How to parse JSON string via command line on Linux

If you often deal with JSON-formatted texts from the command line or in shell scripts, you may wonder if there is any command-line utility which can parse JSON string. A command-line JSON parser can be handy when you test or debug JSON web services. You can feed JSON-formatted responses from web services into the command-line JSON parser, thereby easily inspecting otherwise hard-to-read JSON responses or extracting individual objects from them.

In this tutorial, I will describe how to parse JSON string from the command line.

On Linux, there is a command-line JSON processor called jq which does exactly that. Using jq, you can parse, filter, map, and transform JSON-structured data effortlessly.

To install jq on Linux, simply download its binary (available for 32-bit and 64-bit system separately) as follows.
$ wget http://stedolan.github.io/jq/download/linux32/jq (32-bit system)
$ wget http://stedolan.github.io/jq/download/linux64/jq (64-bit system)
$ chmod +x ./jq
$ sudo cp jq /usr/bin
The jq binary is also available for Windows and OS X platforms, and its full source code is released under the MIT license.

The following examples illustrate how to parse JSON-structured data with jq.

An example JSON Schema:
$ cat json.txt

{
        "name": "Google",
        "location":
                {
                        "street": "1600 Amphitheatre Parkway",
                        "city": "Mountain View",
                        "state": "California",
                        "country": "US"
                },
        "employees":
                [
                        {
                                "name": "Michael",
                                "division": "Engineering"
                        },
                        {
                                "name": "Laura",
                                "division": "HR"
                        },
                        {
                                "name": "Elise",
                                "division": "Marketing"
                        }
                ]
}
To parse a JSON object:
$ cat json.txt | jq '.name'

"Google"
To parse a nested JSON object:
$ cat json.txt | jq '.location.city'

"Mountain View"
To parse a JSON array:
$ cat json.txt | jq '.employees[0].name'

"Michael"
To extract specific fields from a JSON object:
$ cat json.txt | jq '.location | {street, city}'

{
  "city": "Mountain View",
  "street": "1600 Amphitheatre Parkway"
}


Différences majeures entre Red Hat 6, 7, 8 et 9

Quelles sont les différences majeures entre RHEL 6, 7, 8 et 9 ? Système de fichiers RHEL 6: Par défaut : ext4. Autres : ext2, ext3 supportés...