From 1a9139b8fa64f16fc2ca9dc9bbcd8d2d8bc330f8 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sun, 6 Feb 2022 20:10:11 +0100 Subject: [PATCH] Add jq, curl and bash nodes. --- 20220130131002-jq.org | 27 +++++++++++++++++++++++ 20220130131134-bash.org | 45 +++++++++++++++++++++++++++++++++++++ 20220130133727-curl.org | 49 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 20220130131002-jq.org create mode 100644 20220130131134-bash.org create mode 100644 20220130133727-curl.org diff --git a/20220130131002-jq.org b/20220130131002-jq.org new file mode 100644 index 0000000..e329a29 --- /dev/null +++ b/20220130131002-jq.org @@ -0,0 +1,27 @@ +:PROPERTIES: +:ID: 83908b49-3945-4dce-8b26-2a5e4636df13 +:mtime: 20220130131043 +:END: +#+title: jq + +* Installation +#+BEGIN_SRC shell +apt-get install jq +#+END_SRC + +* [[https://github.com/stedolan/jq/wiki/jq-Language-Description][Description du language jq]] + +* [[https://github.com/stedolan/jq/wiki/Cookbook][Cookbook]] + +* Tips +** Get a object from a list by attribute value +#+BEGIN_SRC shell :results output +raw='[{"name":"dummyNameA","toto":0,"titi":1},{"name":"dummyNameC","toto":2,"titi":3},{"name":"dummyNameB","toto":4,"titi":5}]' +name='dummyNameB' +declare -a infos=($(echo "${raw}" | jq -r '.[] | select(.name | contains("'${name}'")) | (.name) + " " + (.titi|tostring) + " " + (.toto|tostring)')) +echo "infos=${infos[@]}" +#+END_SRC + +#+RESULTS: +: infos=dummyNameB 5 4 + diff --git a/20220130131134-bash.org b/20220130131134-bash.org new file mode 100644 index 0000000..911103d --- /dev/null +++ b/20220130131134-bash.org @@ -0,0 +1,45 @@ +:PROPERTIES: +:ID: 72eb2d10-5b92-4fb7-9e4e-1398bd933335 +:mtime: 20220130133646 +:ctime: 20220130131134 +:END: +#+title: bash + +* Installation +#+BEGIN_SRC shell +apt-get install bash +#+END_SRC + +* Tips +** Initialiser une variable non intialisée ou null +#+BEGIN_SRC shell :output dispay +a= +c='AAA' +${a:='coucou'} +${b:=123} +${c:='coucou'} +echo "a=${a}" +echo "b=${b}" +echo "c=${c}" +#+END_SRC + +#+RESULTS: +| a=coucou | +| b=123 | +| c=AAA | +** Initialiser une variable non initialisée +#+BEGIN_SRC shell :output dispay +a= +c='AAA' +${a='coucou'} +${b=123} +${c='coucou'} +echo "a=${a}" +echo "b=${b}" +echo "c=${c}" +#+END_SRC + +#+RESULTS: +| a= | +| b=123 | +| c=AAA | diff --git a/20220130133727-curl.org b/20220130133727-curl.org new file mode 100644 index 0000000..eaa9e5f --- /dev/null +++ b/20220130133727-curl.org @@ -0,0 +1,49 @@ +:PROPERTIES: +:ID: 5ea61eaa-7f37-464c-aa69-8251de8f81af +:mtime: 20220130135414 +:ctime: 20220130133727 +:END: +#+title: curl + +* Introduction + * Abréviation de Client URL Request Library, + * Librairie écrite en C (/libcurl/) et une Interface en ligne de commande, + * Destinée à récupérer le contenu d'une ressource (désignée à l'aide d'une URL) accessible via un réseau. + * Permet de créer ou modifier une ressource (contrairement à wget), il peut ainsi être utilisé en tant que client REST, + * Nombreux bindings (C++, Java, .NET, Perl, PHP, Ruby...), + * Supporte (/libcurl/) les protocoles DICT, file, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, Telnet et TFTP. + +* Installation +#+BEGIN_SRC shell +sudo apt-get install curl +#+END_SRC + +* Tips +** Obtenir l'en-tête HTTP d'une URL: +#+BEGIN_SRC shell :output dispay +curl -I git.adrien.run +#+END_SRC + +#+RESULTS: +| HTTP/1.1 | 301 | Moved | Permanently | | | | +| Server: | nginx/1.18.0 | (Ubuntu) | | | | | +| Date: | Sun, | 30 | Jan | 2022 | 12:50:54 | GMT | +| Content-Type: | text/html | | | | | | +| Content-Length: | 178 | | | | | | +| Connection: | keep-alive | | | | | | +| Location: | https://git.adrien.run/ | | | | | | +| | | | | | | | +** Problème server de certificats +Pour outrepasser les erreurs de certificat d'un server (certificat auto-signé par exemple), ajouter le paramètre ~--insecure~ +** Pour obtenir le code HTTP de retour +#+BEGIN_SRC shell :output display +result=$(curl -s -o /dev/null -w \"%{http_code}\" https://git.adrien.run) +echo $result +#+END_SRC + +#+RESULTS: +: 200 + +* Références + * [[https://curl.se/docs/manpage.html][Man page]] + * [[https://yurisk.info/2020/03/13/curl-cookbook/][Yuri Slobodyanyuk curl cookbook]]