diff --git a/troubleshooting/linux.md b/troubleshooting/linux.md index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0b896054b749104b653780c90ac4876a8e392c61 100644 --- a/troubleshooting/linux.md +++ b/troubleshooting/linux.md @@ -0,0 +1,389 @@ +## Gestion de fichiers + + + +### Création de fichiers en doublons pour autoimport par exemple + +``` +for (( i=1 ; i<=1000 ; i++ )); do cp /in/courrier/tessi_videocodage/import/C_0.pdf /in/courrier/tessi_videocodage/import/C_0$i.pdf; done +``` + + + +### Copier 1 fichier dans n répertoires + +``` + for i in $(ls); do cp sourcefile $i; done +``` + + autre exemple : + +``` + for i in $(ls); do cp post-commit $i"/hooks"; done +``` + +### Copier une liste de répertoires importante + +``` +ls -1 /home/maarch/source | xargs -i cp -R /home/maarch/source/{} /home/maarch/destination +``` + + + +### Supprimer tous les répertoires .svn + +``` +find . -name ".svn" -type d -exec rm -Rf {} \; +``` + + + +### Rechercher un répertoire + +``` +find / -type d -name 'httpdocs' +``` + + + +### Recherche des fichiers plus vieux de 10 jours + +``` +find /srv/backups/gandibackups_from_scp -maxdepth 1 -type f -atime +10 +``` + +### Rechercher les derniers fichiers modifiés + +``` +find /var/www/html/oem/ -not -path '*.svn/*' -mmin -120 +``` + +ou + +``` +find /mydir -type f -mtime -1 -print +``` + + + +### Recherche une chaine de caractère sur tout le système + +``` +cd / +grep -r 'laurent.giovannoni@maarch.org' * > result_search +``` + + + +### Suppression de fichier ou de répertoire avec liste d'exclusion depuis ls + +``` +rm -Rf $(ls | grep -v 'wordpress\|phpmyadmin') +``` + + + +### Compter le nombre d'éléments dans un répertoire + +``` +ls -Al /home/maarch/source | wc -l +``` + + + +### Compter le nombre de fichiers XML dans un répertoire et ses sous-répertoires : + +``` +find /opt/maarch/imports/autoimport/CGR_REPRISE_COMPTA -name '*.xml' | wc +``` + + + +### Remplacer des caractères (tokens) dans plusieurs fichiers + +``` +sed -i -e "s/PASSWORD_MAIL_DSAF/lemotdepasse\!test/g" *.XML +``` + + + +### Remplacer du texte dans une série de fichiers répartis dans des dossiers + +``` +find /var/www/html -type f -exec sed -i 's/5432/5434/g' {} \; +``` + + + +### liste des fichiers créer + +il y a moins de 12 jours, exclusion de l'extension .cache et du répertoire www/maarch.com/* + +``` +sudo find www/ -type f \( ! -iname "*.cache" ! -iname "*.pyc" ! -iname "*.png" ! -path "www/maarch.com/*" ! -path "www/demo.maarch.org/entreprise_*" ! -path "www/demo.maarch.org/cilbox/*" \) -atime -1 > result + +sudo find www/ -type f -atime -5 > result +``` + + + +### Liste des fichiers avec juste la taille (format lisible) et le nom + +``` +ls -lh | awk '{print $5, $9}' +``` + + + +## Compression et décompression + +### création d'un tar.gz + +``` + tar -zcvf votre_archive.tar.gz votre_dossier/ +``` + + + +### Décompresser un tar.gz + +``` + tar -zxvf votre_archive.tar.gz -C votre_dossier_cible/ +``` + + + +### Extraire un fichier spécifique d'un tar.gz + +``` + tar -zxvf indexes_20180429T203402.tar.gz "indexes/45" +``` + + + +### Compression 7z + +``` +7z a -y -mx -t7z zz-Archives.7z zz-Archives/ +``` + + + +### unzip odt + +``` +zip -0 -X ../my-document.odt +zip odt +zip -r ../my-document.odt * -x mimetype +``` + + + +## Réseaux + +### liste des ports utilisés : + +``` +netstat -ntlp | grep LISTEN +``` + + + +### Les processus écoutant sur un port + +``` +lsof -i:4444 -> +``` + + + +### redémarrer réseau + +``` +sudo ifdown -a + +sudo ifup -a + +sudo dhclient + +sudo start network-manager + +sudo /etc/init.d/network-manager restart +``` + + + + + +## Configuration de PHP + +------ + +Configuration et switch de versions + +### #switch to php7.1 + +``` +sudo a2dismod php5.6 +sudo a2enmod php7.1 +sudo service apache2 restart +sudo mv /usr/bin/php /usr/bin/php_BAK +sudo rm /usr/bin/php +sudo ln -s /usr/bin/php7.1 /usr/bin/php +``` + + + +### #switch to php7 + +``` +sudo a2dismod php5.6 +sudo a2enmod php7.0 +sudo service apache2 restart +``` + + + +### #switch to php5.6 + +``` +sudo a2dismod php7.1 +sudo a2enmod php5.6 +sudo service apache2 restart +sudo mv /usr/bin/php /usr/bin/php_BAK +sudo rm /usr/bin/php +sudo ln -s /usr/bin/php5.6 /usr/bin/php +``` + +## Increase size of request in apache for REST webservices + +``` +#LimitRequestFields 32767 +#LimitRequestFieldSize 12392 +LimitRequestLine 10000000000000000 +``` + + + +## Docker + +### Liste des images locales + +``` +docker images +``` + +### Lancer la construction de dockerfile + +``` +docker build . -t maarchcourrier +``` + +### Lancer sh pour un container + +``` +docker exec -it maarchcourrier-develop /bin/bash +``` + + + +## PostgreSQL + +### Supprimer toutes les sockets ouvertes par apache pour postgres + +``` +netstat -anp | grep --regexp="5432" | grep apache2 | awk -F" " '{print $7}' | awk -F"/" '{print $1}' + +echo kill $(sudo netstat -anp | grep --regexp="5432" | grep apache2 | awk -F" " '{print $7}' | awk -F"/" '{print $1}') +``` + + + +### Créer un cluster postgres + +``` +su - +mkdir /opt/postgtresql +chown -R postgres. /opt/postgtresql +su postgres +/usr/lib/postgresql/11/bin/initdb -D /opt/postgtresql + +#Succès. Vous pouvez maintenant lancer le serveur de bases de données en utilisant : +cd /opt/postgresql +``` + + + +### Créer un fichier de trace + +``` +/usr/lib/postgresql/11/bin/pg_ctl -D /opt/postgtresql -l fichier_de_trace start +``` + + + +## Autres + +### Exécuter plusieurs fois le même fichier php + +``` +for (( i=1 ; i<=10 ; i++ )); do php test_ws_store_resource.php; done +``` + +### Liste des paquets installés + +``` +sudo dpkg-query -l | grep xdebug +``` + +### Tuer tous les processus d'un utilisateur + +``` +ps -aef | grep ^www-data | awk '{ print "kill -9 " $2 }' | sh +``` + +### Signer une applet java avec un certificat + +``` +openssl pkcs12 -in ~/OS201403208071.pfx -out mypenfile.pem + +openssl pkcs12 -export -in mypenfile.pem -out mykeystore.p12 -name "MyCert" + +jarsigner -storepass MaarchCertif2014 -tsa http://timestamp.globalsign.com/scripts/timestamp.dll-storetype pkcs12 -keystore mykeystore.p12 NetBeansProjects/maarchCM/dist/maarchCM.jar "MyCert" + +cd /home/lgi/NetBeansProjects +jarsigner -storepass MaarchCertif2014 -keystore ../mykeystore.p12 -tsa http://timestamp.globalsign.com/scripts/timestamp.dll ../NetBeansProjects/maarchCM/dist/maarchCM.jar "mydomain" +``` + + + +### Vérifier la langues + +``` +dpkg-reconfigure locales +``` + +## + +### Convertir un pdf en imagette png thumbnails + +``` +convert -thumbnail 800x1200 -background white -alpha remove install/samples/res_attachments/invitation.pdf install/samples/tnl/invitation.png +``` + + + +### Gestion de wikijs + +lancement + +``` +node wiki start +``` + +arrêt + +``` +node wiki stop +``` +