Skip to content

Instantly share code, notes, and snippets.

@StudioEtrange
StudioEtrange / lvm-commands.sh
Last active April 2, 2018 21:56
LVM and disk commands
# List block devices
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 238.5G 0 disk
├─sda1 8:1 0 200M 0 part /boot/efi
├─sda2 8:2 0 500M 0 part /boot
└─sda3 8:3 0 237.8G 0 part
├─fedora-root 253:0 0 50G 0 lvm /
├─fedora-swap 253:1 0 2G 0 lvm [SWAP]
└─fedora-home 253:2 0 185.9G 0 lvm
@StudioEtrange
StudioEtrange / is_sourced.sh
Created March 28, 2018 23:06
shell detect if sourced
# https://stackoverflow.com/a/28776166
sourced=0
if [ -n "$ZSH_EVAL_CONTEXT" ]; then
case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac
elif [ -n "$KSH_VERSION" ]; then
[ "$(cd $(dirname -- $0) && pwd -P)/$(basename -- $0)" != "$(cd $(dirname -- ${.sh.file}) && pwd -P)/$(basename -- ${.sh.file})" ] && sourced=1
elif [ -n "$BASH_VERSION" ]; then
[ "$0" != "$BASH_SOURCE" ] && sourced=1
else # All other shells: examine $0 for known shell binary filenames
# Detects `sh` and `dash`; add additional shell filenames as needed.
@StudioEtrange
StudioEtrange / smtp_gmail
Created November 28, 2018 00:17
A note about using gmail as a relay
A note about using gmail as a relay
Gmail by default does not allow email clients that don't use OAUTH 2 for authentication (like Thunderbird or Outlook).
First you need to enable access to "Less secure apps" on your google settings.
Serveur de courrier entrant (IMAP) imap.gmail.com
SSL requis : oui
Port : 993
@StudioEtrange
StudioEtrange / Copy preserve attributes
Last active February 2, 2019 10:05
Copy preserve attributes
Copy FOLDER_1 into PATH_B and preserve all attributes
sudo rsync -avihXP --info=progress2 --stats /PATH_A/FOLDER_1/ /PATH_B/
* use --dry-run to test
* for encoding char problems between Mac/Linux : https://serverfault.com/questions/638316/rsync-iconv-option-on-mac-not-working-sync-from-remote-linux-server-to-local
** rsync initiated from Mac : --iconv=utf-8-mac,utf-8
** rsync initiated from Linux : --iconv=utf-8,utf-8-mac
@StudioEtrange
StudioEtrange / bash_var_defined_undefined.sh
Created March 31, 2019 21:18
bash var defined / undefined
#https://stackoverflow.com/a/10965292
[ -n "$var" ] && echo "var is set and not empty"
[ -z "$var" ] && echo "var is unset or empty"
[ "${var+x}" = "x" ] && echo "var is set" # may or may not be empty
[ -n "${var+x}" ] && echo "var is set" # may or may not be empty
[ -z "${var+x}" ] && echo "var is unset"
[ -z "${var-x}" ] && echo "var is set and empty"
@StudioEtrange
StudioEtrange / ssh_key_based_authentification.md
Last active October 31, 2025 20:12
Configure ssh key based authentification

1. SSH key based authentification

1.1. Summary

Guide to :

  • Autorize SSH connection from a local machine to a distant SSH machine without using a password
  • Configure VSCode to use this SSH configuration

Some other informations :

@StudioEtrange
StudioEtrange / bash_debug_time.sh
Last active January 24, 2020 04:51
Debug execution time of bash script
# Solutions from https://stackoverflow.com/a/20855353
# SOLUTION 1 : analyse at the current level of execution (do not step into code)
# get https://www.f-hauri.ch/vrac/cours_truc-et-astuces_2012-04-03/add/elap.bash-v2
@StudioEtrange
StudioEtrange / docker-compose-traefik-route-to-url.yml
Last active January 31, 2022 17:11
traefik sample for route to an external URL - add a blog.mondomain.com route to http://blog:4000
traefik:
image: traefik:v2.1.6
container_name: traefik
volumes:
- "traefik.enable=true"
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik-conf.yml:/etc/traefik/traefik.yml
- ./traefik-services.yml:/etc/traefik/services.yml
labels:
- "traefik.http.routers.blog.entrypoints=web_main"
# launch a shell with an empty env
# https://unix.stackexchange.com/a/291913
env -i bash --noprofile --norc
# source var file and show a specific var
env -i bash --noprofile --norc -c ". somefile.sh; echo $VAR;"
# backup/restore env
# https://unix.stackexchange.com/questions/284382/export-save-and-import-source-shell-variables
@StudioEtrange
StudioEtrange / count_all_crontab.sh
Created January 27, 2021 19:16
count number of active task inside of all user crontab
# count number of active task inside of all user crontab
# sample with excluding a string containing "str"
for c in $(sudo ls /var/spool/cron); do sudo crontab -u $c -l 2>/dev/null | grep -v -e '^$' | grep -v -e '^#' | grep -v "crontab;" | grep -v "str"; done | wc -l