blog
Table des matières
- 2026:
- 2025:
4 billet(s) pour septembre 2026
| Notes HTTP Strict Transport Security - HSTS | 2026/09/18 11:04 | Jean-Baptiste |
| Notes GNU Linux GPU carte graphiques | 2026/09/08 15:49 | Jean-Baptiste |
| Notes GNU Linux graphique | 2026/09/08 15:42 | Jean-Baptiste |
| Notes urlencoding - passer des mots de passe en HTTPS | 2026/09/03 17:58 | Jean-Baptiste |
signify-openbsd
Liens :
Une alternative à GPG (que pour signer).
C'est fait pour signer des petits fichiers/paquets
Pour des grands fichiers l'idée et de faire un sha256sum et de signer ce fichier de hash.
Dans le dépôt testing
apt-get install signify-openbsd
-p : Public key -s : Secret key -m : Message -x : Signature -G : Generate key pair -S : Sign -V : Verify
Générer une paire de clef
signify-openbsd -G -n -p key.pub -s key.sec
Signer
signify-openbsd -S -s key.sec -m message.txt
Vérifier la signature
signify-openbsd -V -p key.pub -m message.txt
Exemple
find . -type f -exec sha512sum {} \; > sha512sum signify-openbsd -S -s ../key.sec -m sha512sum
Shelldap
Un shell LDAP pour se simplifier la vie
Installation
apt-get update apt-get install shelldap
Configuration
Exemple 1
~/.shelldap.rc
server: localhost:389 binddn: cn=admin,dc=ce,dc=domain,dc=net bindpass: ***MOT_DE_PASSE*** basedn: ou=users,dc=ce,dc=domain,dc=net tls: yes
Exemple 2
~/.shelldap.rc
server: 192.168.2.10:389
binddn: admin
bindpass: P@ssw0rd
Shell script LVM lsblk get vgfree space without root privileges
vg_free.sh
#! /bin/bash # Creative Commons CC0 Public Domain Licence set -euo pipefail IFS=$' \t\n' export LC_ALL=C SCRIPT_NAME="$(basename "$0")" usage() { cat <<-EOF Usage: $SCRIPT_NAME [ VG_NAME ] Usage: $SCRIPT_NAME [ -a|--all ] Usage: $SCRIPT_NAME [ -h|--help ] $SCRIPT_NAME display volume groups free space in MiB for non-root users. $SCRIPT_NAME [ VG_NAME ] Is equivalent : sudo vgs --readonly --noheadings --units=m [ VG_NAME ] -o vgfree $SCRIPT_NAME --all Is equivalent : sudo vgs --readonly --noheadings --units=m -o vgname,vgfree EOF } command_exists() { if ! command -v "$1" >/dev/null 2>&1 ; then echo -e "Missing command : $1\nAborting." >&2 exit 127 fi } calc_sum() { awk '{s+=$1} END {printf "%.0f", s}' "$*" } get_vg_size() { local VG_NAME=$1 lsblk -b -i | grep -B1 -E -e '[|`]-'"${VG_NAME/-/-*}-" | awk '/part|disk|crypt/ { print $4 }' | calc_sum } get_lv_total_size() { local VG_NAME=$1 #lsblk -p -b -o NAME,SIZE -J --nodeps "/dev/${VG_NAME}"/* |jq '.blockdevices[].size |tonumber' lsblk -p -b -n -o SIZE --nodeps "/dev/${VG_NAME}/"* | calc_sum } get_vg_list() { # shellcheck disable=SC2012 ls -1 /dev/mapper/ | awk '/-/{print $1}' | sed -e 's/-[^-]*$//' -e 's/--/-/' | sort -u } get_vgfree() { local VG_NAME=$1 local -i VG_SIZE local -i LV_TOTAL_SIZE VG_SIZE="$(get_vg_size "$VG_NAME")" LV_TOTAL_SIZE="$(get_lv_total_size "$VG_NAME")" echo "$(( ( VG_SIZE - LV_TOTAL_SIZE ) /1024/1024 ))" } check_inputs() { local VG_NAME=$1 if [[ ! -d "/dev/${VG_NAME}" ]] then echo "Volume group $VG_NAME not found" >&2 exit 5 fi } main() { local VG_NAME=${1-} local -i VG_FREE command_exists lsblk if [[ "$NOARGS" -eq 1 ]] then for VG in $(get_vg_list) do VG_FREE="$(get_vgfree "$VG")" printf " %-8s %10.2fm\n" "$VG" "$VG_FREE" done else VG_FREE="$(get_vgfree "$VG_NAME")" echo " ${VG_FREE}.00m" fi } if [[ $# -eq 0 ]] then echo "$SCRIPT_NAME: missing operand" >&2 echo "Try '$SCRIPT_NAME --help' for more information." >&2 exit 1 fi while [ "${1-}" != "" ]; do case $1 in # --debug ) DEBUG=1 # ;; -a | --all ) shift NOARGS=1 main ;; -h | --help ) usage exit 0 ;; --) # End of all options shift break ;; -*) echo "SCRIPT_NAME: invalid option" >&2 echo "Try '$SCRIPT_NAME --help' for more information." >&2 exit 1 ;; *) check_inputs "$1" NOARGS=0 main "$1" ;; esac shift done
Sinon il est toujours possible de s'en sortir avec quelques commandes
lsblk -b -i |grep -B1 vg00 |awk '/part|disk/crypt/ { print $4 }' | awk '{s+=$1} END {printf "%.0f", s}' lsblk -b -i |grep -B1 vg00 |awk '/lvm/ { print $4 }' |awk '{s+=$1} END {printf "%.0f", s}'
Shell script - exemple de wrapper - exec rgrep
Voir aussi wrapper compilés :
- /usr/lib64/nagios/plugins/negate
/usr/bin/rgrep
#!/bin/sh exec grep -r "$@"
/bin/fgrep
#!/bin/sh exec grep -F "$@"
Voir man bash
ou avec une fonction
function rgrep() { grep -r "$@" }
Autre exemple
tar () { command tar "$@" --no-same-owner --no-same-permissions; return $?; }
Scripting shell bash et tests unitaires avec bats
Voir :
apt-get install -y --no-install-recommends bats
test/spec.bats
#!/usr/bin/env bats set -euo pipefail @test "Check apache2 is up" { ps aux | grep "apache2" }
test/spec.bats
#! /usr/bin/env bats set -eu setup() { # Appelée avant chaque test unitaire #echo "$(date --iso-8601=second BEGIN $BATS_TEST_NUMBER $BATS_TEST_NAME" > /dev/stdin true } teardown() { # Appelée après chaque test unitaire #echo "$(date --iso-8601=second) END $BATS_TEST_NUMBER $BATS_TEST_NAME" > /dev/stdin true } setup_file() { # Appelée une seule fois au début du lancement de ce script echo "$(date --iso-8601=second) BEGIN $(basename $BATS_TEST_FILENAME)" > /dev/stdin } teardown_file() { # Appelée une seule fois en dernier lors de l’exécution de ce script sleep 1 echo -e "\b$(date --iso-8601=second) END $(basename $BATS_TEST_FILENAME)" > /dev/stdin } ### Exemple de tests @test "prereq - create account" { ansible -b -i tests/inventory -m user -a 'name=testplop' all } @test "Check required fields" { ansible-playbook --check tests/test.yml -i tests/inventory | grep -q 'NameError.' }
Dépendance et condition
test/spec.bats
foo() { echo foobar > /tmp/plop } @test "foobar" { run foo }
Autres
tests/spec.sh
#! /bin/bash set -eu if [ -z "${ALREADY_RUN:-}" ] then export ALREADY_RUN=yes fi
test/spec.bats
#! /usr/bin/env bats set -eu load spec.sh @test "clean" { if [ ! -z "${ALREADY_RUN:-}" ] then ssh server -- sudo find /opt/app1/ -type f -delete fi }
blog.txt · Dernière modification : de 127.0.0.1
