[SHELL/BASH Scripting]
# My snipets for shell scripting #shell #sh #bash #unix #terminal
# Autostart script in debian linux
https://debian-administration.org/article/28/Making_scripts_run_at_boot_time_with_Debian
# Simple interrupt
read -p "Press any key to continue " -n 1
# Interrupt with timeout
read -p "Press any key to continue (autocontinue in 30 seconds) " -t 30 -n 1
# Rename multiple files (.txt to .lst)
for file in *.txt; do mv ${file%.txt}{.txt,.lst}; done
# Sequenz simple
for srv in server{1..3}; do echo $srv;done
server1
server2
server3
# Sequenze with format
for srv in `seq -w 1 4`; do echo server${srv};done
server01
server02
server03
server04
# Working with strings
$ STRING="username:homedir:shell"
$ echo "$STRING"|cut -d ":" -f 3
shell
$ echo "${STRING##*:}"
shell
# Check env
command -v docker > /dev/null 2>&1 || { echo "[ERROR] Please install docker first"; exit 1; }
command -v jq > /dev/null 2>&1 || { echo "[ERROR] Please install jq first"; exit 1; }
command -v socat > /dev/null 2>&1 || { echo "[ERROR] Please install socat first"; exit 1; }
command -v curl > /dev/null 2>&1 || { echo "[ERROR] Please install curl first"; exit 1; }
# Check system options
if [ -x $(command -v systemctl) ]; then
INIT_SYSTEM=systemd
else
INIT_SYSTEM=sysvinit
echo "[ERROR] Only systemd is supprted at the moment"
exit 1
fi