Ici, de la documentation admin sys qui a pu servir au projet tout au long de sa vie, un peu en vrac.

SSH

  ssh -L 8000:localhost:8888 user@serveur # redirige le port distant 8888 sur le port local 8000
  

Bash utils

  • Commandes en vrac :
  rsync -a /path/to/source/ /path/to/destination/ # copy source to destination with overwrite
rsync -au /path/to/source/ /path/to/destination/ # ... with older files only overwrite
rsync -a --ignore-existing /path/to/source/ /path/to/destination/ # ... with no overwrite
  
  openssl x509 -noout -text -in /etc/ssl/cert.pem # voir le contenu d'un certificat X.509 (HTTPS)
  
  tar --exclude="*/*" -tf file.tar # liste le contenu d'une archive, répertoires uniquement, profondeur=1
  
  cp -r -u newsrc/* oldsrc/ # copie les fichiers et répertoires plus récents d'un répertoire à un autre
  

Docker

  • Script mettant à jour le fichier /etc/hosts avec les adresses et noms des conteneurs Docker :
  #!/bin/bash
# Depuis https://github.com/dr-co/docker-resolver/blob/master/docker-hosts.sh
 
if ! test -z "$1"; then
    exec "$@"
fi
 
set -e
 
MARKER='##- container.resolver -##'
TEMPFILE=`tempfile`
 
cleanup() {
   grep -v "$MARKER" /etc/hosts > $TEMPFILE
   cat $TEMPFILE > /etc/hosts
   rm -f $TEMPFILE
}
 
trap "cleanup; exit" EXIT INT TERM
 
while true; do
    grep -v "$MARKER" /etc/hosts > $TEMPFILE
 
    docker ps| while read line; do
        id=`echo $line|awk '{print $1}'`
        name=`echo $line|awk '{print $NF}'`
        ip=`docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 2>/dev/null $id || true`
 
        if test -z "$ip"; then
            continue
        fi
 
        printf  "%-15s %s %-25s $MARKER\n" $ip    $id $name >> $TEMPFILE
    done
 
    EXISTS=`md5sum /etc/hosts|awk '{print $1}'`
    NEW=`md5sum $TEMPFILE|awk '{print $1}'`
 
    if ! test $NEW = $EXISTS; then
        cat $TEMPFILE > /etc/hosts
    fi
 
    sleep ${REFRESH_INTERVAL-10}
done
  
  docker volume create --name <new_volume>
docker run --rm -it -v <old_volume>:/from -v <new_volume>:/to alpine ash -c "cd /from ; cp -av . /to"
docker volume rm <old_volume>
  
  • Commandes en vrac :
  docker compose up --force-recreate --build -d
  

MySQL / MariaDB

  • Changement d’encodage (base et table) :
  ALTER DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  
  • Sauvegarde et restauration (Docker)
  docker exec -i container_name sh -c 'exec mariadb-dump --all-databases -u root -pXXXX' > all.sql # Dump de toutes les bases
docker exec -i container_name sh -c 'exec mariadb-dump -u root -pXXXX database_name' > database_name.sql # Dump d'une seule base
docker exec -i container_name sh -c 'exec mariadb -u root -pXXXX' < dump.sql # Restauration d'un dump (une ou plusieurs bases)
  

Divers

  • Systemctl :
  systemctl list-units --failed
systemctl reset-failed
  
  • Pilote Wi-Fi pour Ubuntu Oracular : Broadcom BCM43xx
  apt-get install broadcom-sta-dkms
modprobe wl
  

Services

MantisBT