Outils pour utilisateurs

Outils du site


blog

Script shell interactif avec boîtes de dialogue (dialog boxes) - Whiptail

Voir :

Voir aussi :

  • dialog

Whiptail est inclus par défaut dans Debian

Exemple de script

dialogBoxes.sh

#! /bin/bash
 
set -o nounset
 
WHIPTAIL='env LANG=C whiptail'
 
#exec 2> /tmp/dlg-log-"$(date +%Y%m%d%H%M)".err
 
menu1()
{
	$WHIPTAIL --title "NODE" --menu "Choose a hostname" 25 78 16 \
	srv-1 "" \
	srv-2 "" \
	MAIN_MENU "" \
			2>/tmp/dlg-choix
}
 
menu2()
{	
	$WHIPTAIL --title "APP ON/OFF" --menu "On / Off" 25 78 16 \
	1_App_On "" \
	2_App_Off "" \
	MAIN_MENU "" \
			2>/tmp/dlg-choix
}
 
main_menu()
{	
	$WHIPTAIL --title "MAIN MENU" --menu "Select an option" 25 78 16 \
	1_Node "" \
	2_App_Activation "" \
			2>/tmp/dlg-choix
}
 
sortir()
{
	rm -f /tmp/dlg-choix
 	echo -e "\\n\\tBye !"
	exit 0
}
 
 
test_menu_option()
{
CHOIX=$(cat /tmp/dlg-choix)
rm -f /tmp/dlg-choix
 
case $CHOIX in
1_Node)
	menu1
   ;;
2_App_Activation)
	menu2
   ;;
1_App_On)
	echo "App_On ${HOST_SRV:-x}"
	sortir
   ;;
2_App_Off)
	echo "App_Off ${HOST_SRV:-x}"
	sortir
   ;;
MAIN_MENU)
	main_menu
   ;;
srv-1)
	HOST_SRV=1
	menu2
   ;;
srv-2)
	HOST_SRV=2
	menu2
   ;;
"")
	echo "Cancelled by user"
	sortir
   ;;
*)
	echo -e "Option unknown : \"${CHOIX}\""
	exit 2
   ;;
esac
}
 
main_menu
 
while true
do
	test_menu_option
done

Dialog

Exemples

(pv -n image.iso | dd of=/dev/sdb bs=1M && sync) 2>&1 | dialog --gauge "la commande dd est en cours d'exécution, merci de patienter..." 10 70 0
2025/03/24 15:06

Script shell commande timeout

Voir aussi :

A titre d'exemple. Idéalement il faut gérer le timeout avec Ansible

Exemple de code Ansible

    - name: command ldap_search
      become: true
      ansible.builtin.command: |
        /usr/bin/timeout --kill-after=15 10 /usr/bin/ldapsearch -LLL -D cn={{ lookup('env', 'LDAP_USER') }} -b o=unixauth -y /root/.ansible/tmp-files/.ldap.txt uid={{ CDO_ACCOUNT_USER | quote }} dn
      changed_when: false
      check_mode: false
      register: ldapsearch
      environment:
        LANG: C
      failed_when:
        - ldapsearch.rc != 0       # OK
        - ldapsearch.rc != 124     # Timeout. SIGTERM
        - ldapsearch.rc != 137     # Timeout. SIGKILL

    - name: fail when timeout - SIGTERM
      fail:
        msg: "Error_Command_Timeout. Process arrêté par SIGTERM."
      when: ldapsearch.rc == 124

    - name: fail when timeout - SIGKILL
      fail:
        msg: "Error_Command_Timeout. Process arrêté par SIGKILL."
      when: ldapsearch.rc == 137

    - name: fail if ACME user
      fail:
        msg: |
          Error_ElementAlreadyUsed. Nom de compte utilisateur déjà utilisé par ACME {{ CDO_ACCOUNT_USER }}.
      when:
        - ldapsearch.stdout_lines | select('regex', '^dn:') | list is regex(',o=unixauth')
        - not allow_ldap_acme

Concernant Ansible voir aussi https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_async.html

async pool timeout

play1.yml

#!/usr/bin/ansible-playbook
 
---

- name: test
  hosts: localhost
  gather_facts: false
 
  # TIMEOUT_MAX = async	                # when poll != 0
  # TIMEOUT_MAX = retries x delay	# when poll == 0

  tasks:
    - name: Command
      shell: |
        sleep 5
        date >> /tmp/date.log
      poll: 0           # When pool is a positive value, the playbook will still block on the task until it either completes, fails or timeout
      async: 2          # if poll != 0 : fail when task is longer than async value
      register: cmd_sleep

    - name: DEBUG 10
      debug:
        msg: "Command en cours d'execution"

    - name: Async_status
      async_status:
        jid: "{{ cmd_sleep.ansible_job_id }}"
      register: job_result
      until: job_result.finished
      retries: 3        # MAX TIMEOUT VAR
      delay: 2          # MAX TIMEOUT VAR

    - name: DEBUG 20
      debug:
        msg: "Execution terminée"
2025/03/24 15:06

Cobbler déploiement Ubuntu ou Debian

Voir :

Notes : Nous n'utiliserons pas debmirror \

Contexte : Nous sommmes sur une CentOS7 (Serveur Cobbler) et nous allons déployer une Ubuntu Server 16.04

Mise-à-jour de la liste des signatures (--os-version)

cobbler signature update

Import de l'ISO montée sur /mnt

mount ubuntu-16.04-server-amd64.iso /mnt
cobbler import --name=ubuntu-server --path=/mnt --breed=ubuntu --os-version=xenial --arch=x86_64
umount /mnt

Copie du profile original

cobbler profile copy --name=ubuntu-server-x86_64 --newname=ubuntu-server-16.04.vm

Modif du nouveau profile

cobbler profile edit --name=ubuntu-server-16.04.vm --proxy=http://192.168.100.3:8080/ --virt-path=/var/lib/libvirt/images

Modif du nouveau profile (pour visrsh console et autre)

cobbler profile edit --name=ubuntu-server-16.04.vm --kopts-post="console=ttyS0,115200n8 ipv6.disable=1 vga=0x317" --kopts="console=ttyS0,115200n8 ipv6.disable=1"

vga=0x317 est déprécié, utiliser à la place : gfxpayload=1024x768x16,1024x768

Copie de la “distro” d'origine, car nous allons la modifier

cobbler distro copy --name ubuntu-server-x86_64 --newname=ubuntu-server-x86_64-orig

Modification du Kickstart Metadata de la distro ubuntu-server-x86_64 \ Nous changeons la ligne suivante :

tree=http://@@http_server@@/cblr/links/ubuntu-server-x86_64 \ en \ tree=http://fr.archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64

cobbler distro edit --name=ubuntu-server-x86_64 --ksmeta='tree=http://fr.archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64'

Copie du fichier d'exemple preseed (sample.seed) Nous modifierons la copie de la manière suivante :

/var/lib/cobbler/kickstarts/ubuntu-server-16.04.seed

d-i mirror/http/hostname string fr.archive.ubuntu.com
d-i mirror/http/directory string /ubuntu
cp -p /var/lib/cobbler/kickstarts/sample.seed /var/lib/cobbler/kickstarts/ubuntu-server-16.04.seed
sed -i -e 's%^\(d-i mirror/http/hostname string\).*%\1 fr.archive.ubuntu.com%' /var/lib/cobbler/kickstarts/ubuntu-server-16.04.seed
sed -i -e 's%^\(d-i mirror/http/directory string\).*%\1 /ubuntu%' /var/lib/cobbler/kickstarts/ubuntu-server-16.04.seed

A faire aussi

cp -p /var/lib/cobbler/scripts/preseed_late_default /var/lib/cobbler/scripts/preseed_late_ubuntu-server-16.04
sed -i -e 's/preseed_late_default/preseed_late_ubuntu-server-16.04/' /var/lib/cobbler/kickstarts/ubuntu-server-16.04.seed

On modifie le script de postinstall

/var/lib/cobbler/kickstarts/ubuntu-server-16.04.seed

echo "$hostname" > /etc/hostname
/bin/hostname $hostname
 
$SNIPPET('download_config_files')
$SNIPPET('kickstart_done')

Lier le nouveau fichier kickstart/preseed au profile

cobbler profile edit --name=ubuntu-server-16.04.vm --kickstart=/var/lib/cobbler/kickstarts/ubuntu-server-16.04.seed

Puis

cobbler sync

L'adresse MAC un un chiffre hexadécimal écrit sous la forme '52:54:XX:XX:XX:XX' (où X est un chiffre en base 16 entre 0 et F)

cobbler system add      --name=${HostName}                                      \
                        --gateway=${Gateway}                                    \
                        --hostname=${HostName}                                  \
                        --ipv6-autoconfiguration=false                          \
                        --power-type=ack_manual                                 \
                        --profile=ubuntu-server-16.04.vm                        \
                        --repos-enabled=false                                   \
                        --status=production                                     \
                        --virt-auto-boot=0                                      \
                        --virt-type=kvm
 
cobbler system edit     --name=${HostName}                                      \
                        --interface=ens3                                        \
                        --ip-address=${IP_Addr}                                 \
                        --mac=$Mac                                              \
                        --netmask=${NetMask}                                    \
                        --static=1

Retour arrière

Effacement de la nouvelle distro

Exemple à adapter

cobbler system remove --name=ttest01
cobbler profile remove --name=ubuntu-server-16.04.vm
cobbler profile remove --name=ubuntu-server-x86_64
cobbler distro remove --name=ubuntu-server-x86_64
cobbler repo remove --name=ubuntu-server-x86_64
2025/03/24 15:06

Cobbler déploiement Debian

Debian

mount /home/debian-8.7.1-amd64-DVD-1.iso /mnt/iso
cobbler import --name=debian --path=/mnt/iso --breed=debian --os-version=jessie --arch=x86_64
 
cobbler sync
 
cobbler profile copy --name=debian-x86_64 --newname=debian-x86_64_custom
cobbler profile edit --name debian-x86_64_custom --virt-type=kvm --virt-bridge=virbr0 \
	--kopts="debian-installer/allow_unauthenticated=true console=tty0 console=ttyS0,115200n8 net.ifnames=0 biosdevname=0 ipv6.disable=1 vga=0x317" \
	--kopts-post="console=tty0 console=ttyS0,115200n8 net.ifnames=0 biosdevname=0 ipv6.disable=1 vga=0x317" \
	--virt-file-size=30 --virt-ram=2048
cobbler system add --profile=debian-x86_64_custom --name=debtest1 --mac=52:54:00:DD:EE:FF --interface=eth0 --virt-type=kvm #--virt-file-size=30 --virt-ram=2048
 
cd 
wget http://ftp.fr.debian.org/debian/dists/jessie/main/installer-amd64/current/images/netboot/netboot.tar.gz
cd  /var/www/cobbler/links/debian-x86_64/install/
mkdir netboot
cd netbook
tar xvf ~/netboot.tar.gz

/var/www/cobbler/links/debian-x86_64/.treeinfo

[general]
family = Debian
timestamp = 1272326522.13
totaldiscs = 1
version = 8
discnum = 1
packagedir = dists
arch = x86_64
 
[images-x86_64]
kernel = install/netboot/debian-installer/amd64/linux
initrd = install/netboot/debian-installer/amd64/initrd.gz
cobbler repo copy --name=debian-x86_64 --newname=debian-x86_64_custom
cobbler repo edit --name=debian-x86_64_custom --mirror=http://192.168.21.1/debian8/dists/jessie 
KVM
export COBBLER_SERVER=192.168.21.3
LANG=C koan --virt --wait=-1 --system=debtest1 --server=192.168.21.3

Clean

cobbler system remove --name debtest1
 
cobbler profile remove --name debian-x86_64_custom  
cobbler profile remove --name debian-x86_64
cobbler profile remove --name debian-gtk-x86_64
 
cobbler distro remove --name debian-x86_64_custom
cobbler distro remove --name debian-x86_64
cobbler distro remove --name debian-gtk-x86_64
 
cobbler repo remove --name debian-x86_64_custom
cobbler repo remove --name debian-x86_64
cobbler repo remove --name debian-gtk-x86_64
2025/03/24 15:06

CMS PHP Wordpress

Source : https://codex.wordpress.org/Debugging_in_WordPress

Debug Wordpress

wp-config.php

 // Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
 
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
 
// Disable display of errors and warnings 
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
 
// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define( 'SCRIPT_DEBUG', true );

Sécurité

Scan
sudo apt-get install ruby-rubygems ruby-dev
export PATH="$PATH":/home/jibe/.local/share/gem/ruby/3.0.0/bin
gem install --user-install wpscan
wpscan --url https://wp.acme.fr -o wpscan_wp.acme.fr.txt
2025/03/24 15:06
blog.txt · Dernière modification : de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki