Všelijaké mé (eventuelně užitečné či naprosto zbytečné) scripty.

Shellboard

Jazyk: Bash
Účel: Zobrazovat užitečné informace na serveru, aby na první pohled bylo zřejmé, zda server vyžaduje nějakou akci. Předpokládá běh na Arch Linuxu.

clear
# COLOR DEFINITIONS
# cl = text color only; bg = background color only; bo = behaviour option
cl_darkred="\e[31m"
cl_magneta="\e[35m"
cl_lmag="\e[95m"
cl_cyan="\e[36m"
cl_lcyan="\e[96m"
cl_lred="\e[91m"
cl_lgreen="\e[92m"
cl_clear="\e[0m"
bg_red="\e[41m"
bg_magneta="\e[45m"
bg_lgreen="\e[102m"
bg_red="\e[41m"
bo_blink="\e[5m"

bold=$(tput bold)
normal=$(tput sgr0)
okmessage="[$cl_lgreen OK $cl_clear]"
nonokmessage="[$cl_lred$bo_blink X $cl_clear]"
interface1="enp0s25"
interface2="wg0"
disk1="/dev/sda2"

while true; do
    # Move the cursor to the beginning of the script's output
    tput cup 0 0

    echo -e "${bold}$cl_cyan:: SYSTEM OVERVIEW ::${normal}$cl_clear"
    echo -e " ${bold}UPTIME:${normal}         $(uptime -p)"
    echo -e " ${bold}RAM:${normal}            $(free -h | awk 'NR==2{printf "Used RAM: %s/%s (%.1f%%)\n", $3, $2, $3*100/$2}')"
    echo -e " ${bold}TEMPERATURE:${normal}    $(sensors | grep temp1)"
    echo -e " ${bold}LAST UPDATE:${normal}    $(cat /var/log/pacman.log | grep -i "starting full system upgrade" | tail -n 1 | cut -c 2-25)"
    echo -e " ${bold}USERS ONLINE:${normal}   $(who | awk '{printf "%s ", $1}')"
    echo -e " ${bold}USERS TODAY:${normal}    $(last -w | grep "pts" | grep -E "$(date '+%a %b %d')" | awk '{print $1}' | sort -u | tr '\n' ' ')"
    echo -e " ${bold}FAIL2BAN:${normal}       $(fail2ban-client status sshd | grep Currently | grep banned | cut -c 5-60)"
    echo -e " ${bold}FAIL2BAN:${normal}       $(fail2ban-client status sshd | grep Currently | grep failed | cut -c 5-60)"
    echo -e "${bold}$cl_cyan:: SERVICES ::${normal}$cl_clear"
    echo -e " ${bold}MUMBLE-SERVER:${normal}  $(systemctl is-active --quiet mumble-server && echo -e "$okmessage" || echo -e "$nonokmessage")"
    echo -e " ${bold}APACHE/WEB:${normal}     $(systemctl is-active --quiet httpd && echo -e "$okmessage" || echo -e "$nonokmessage")"
    echo -e " ${bold}FAIL2BAN:${normal}       $(systemctl is-active --quiet fail2ban && echo -e "$okmessage" || echo -e "$nonokmessage")"
    echo -e " ${bold}SERVERUPDATE:${normal}   $(systemctl is-active --quiet serverupdate && echo -e "$okmessage" || echo -e "$nonokmessage")"
    echo -e "${bold}$cl_cyan:: TRAFFIC TODAY ::${normal}$cl_clear"
    echo -e " ${bold}LAN/WAN:${normal}        $(vnstat -i $interface1 | grep today | cut -c 19-100)"
    echo -e " ${bold}WIREGUARD:${normal}      $(vnstat -i $interface2 | grep today | cut -c 19-100)"
    echo -e "${bold}$cl_cyan:: FAILED LOGGINS ::${normal}$cl_clear"
    lastb -w -n 10

    # Sleep for 5 seconds before refreshing
    echo -e "${bold}$cl_cyan:: CONNECTED VPN CLIENTS ::${normal}$cl_clear"
    wg show | grep endpoint
    sleep 5
done

CSSHS

Jazyk: Bash
Účel: Zálohovat data pomocí „rsync“ přes SSH na server.

#####################################################################
# NOTE: It's recommended to set up an SSH KEY-based autorization, otherwise rsync will be asking for password - ALWAYS

# COLOR DEFINITIONS
# cl = text color only; bg = background color only; bo = behaviour option
cl_darkred="\e[31m"
cl_magneta="\e[35m"
cl_lmag="\e[95m"
cl_cyan="\e[36m"
cl_lcyan="\e[96m"
cl_lred="\e[91m"
cl_lgreen="\e[92m"
cl_clear="\e[0m"
bg_red="\e[41m"
bg_magneta="\e[45m"
bg_lgreen="\e[102m"
bg_red="\e[41m"
bo_blink="\e[5m"

# CONFIGURATION
file_config="csshs_config"
source $file_config

# CONFIGURATION FILE CHECK
function config_file_check()
  {
    echo -e "$cl_lcyan[CSSHS]$cl_cyan Checking configuration file"
    error_found=0
    if [ -e $file_config ]; then
      if grep -q "server=" "$file_config";
  			then
  				echo -e "$cl_cyan Config file check - server: $server $cl_lgreen[✔]$cl_clear"
  			else
  				echo -e "$cl_cyan Config file check - server: not set $cl_lred[x]$cl_clear"
          error_found=1
  		fi

  		if grep -q port= "$file_config";
  			then
  				echo -e "$cl_cyan Config file check - port: $port $cl_lgreen[✔]$cl_clear"
  			else
  				echo -e "$cl_cyan Config file check - port: not set $cl_lred[x]$cl_clear"
          error_found=1
  		fi

  		if grep -q user= "$file_config";
  			then
  				echo -e "$cl_cyan Config file check - user: $user $server $cl_lgreen[✔]$cl_clear"
  			else
  				echo -e "$cl_cyan Config file check - user: not set $cl_lred[x]$cl_clear"
          error_found=1
  		fi

  		if grep -q sec= "$file_config";
  			then
  				echo -e "$cl_cyan Config file check - sec: $sec $server $cl_lgreen[✔]$cl_clear"
  			else
  				echo -e "$cl_cyan Config file check - sec: not set $cl_lred[x]$cl_clear"
          error_found=1
        fi

      if grep -q sync_folders= "$file_config";
    		then
    				echo -e "$cl_cyan Config file check - number of sync folders: ${#sync_folders[@]}"
            echo -e "$cl_cyan Config file check - specified sync folders: ${sync_folders[@]}"
    		else
    				echo -e "$cl_cyan Config file check - sync_folders: not set $cl_lred[x]$cl_clear"
            error_found=1
        fi

        if grep -q target_folder= "$file_config";
    			then
    				echo -e "$cl_cyan Config file check - target_folder: $target_folder $server $cl_lgreen[✔]$cl_clear"
    			else
    				echo -e "$cl_cyan Config file check - target_folder: not set $cl_lred[x]$cl_clear"
            error_found=1
          fi
    else
        echo -e "$cl_cyan Config file check - file doesn't exist $cl_lred[x]$cl_clear"
        error_found=1
    fi

    if [ $error_found -eq "1" ]; then
      echo -e "$cl_cyan Configuration file doesn't meet the expectations, exiting."
      exit
    else
      echo -e "$cl_cyan Configuration file is ok $server $cl_lgreen[✔]$cl_clear"
    fi
  }

function sync_folder_check()
  {
    error_found=0
    echo -e "$cl_lcyan[CSSHS]$cl_cyan Checking sync_folders"
    for d in "${sync_folders[@]}"; do
      if [ -d "$d" ]; then
          echo -e "$cl_cyan Folder $d exists $server $cl_lgreen[✔]$cl_clear"
      else
          echo -e "$cl_cyan Folder $d doesn't exist $cl_lred[x]$cl_clear"
          error_found=1
      fi
  done

  if [ $error_found -eq "1" ]; then
    echo -e "$cl_lcyan[CSSHS]$cl_cyan Some of the directories specified as sync_folders don't exist."
    exit
  else
    echo -e "$cl_lcyan[CSSHS]$cl_cyan sync_folders ok."
  fi
  }

function anti-root_check()
  {
    if [[ $EUID -eq 0 ]]; then
    	echo -e "$cl_lcyan[CSSHS]$cl_cyan It's not recommended to run this script as ROOT.$cl_clear"
    	exit
    else
      :
    fi
  }

function ping_check()
  {
      echo -e "$cl_lcyan[CSSHS]$cl_cyan Performing ping check"
    	if [ "`ping -c 1 $server`" ]; then
        echo -e "$cl_cyan Ping check $cl_lgreen[✔]$cl_clear"
      else
        echo -e "$cl_cyan Ping check $cl_lred[x]$cl_clear"
        echo -e "$cl_lcyan[CSSHS]$cl_cyan Server seems to be unavailable, waiting..."
        sleep 60
        ping_check
      fi
  }

function sync()
  {
    echo -e "$cl_lcyan[CSSHS]$cl_cyan$bo_blink Starting in 3 seconds, press CTRL+C to cancel$cl_clear$cl_cyan"
    sleep 3
    $default_command ${sync_folders[@]} -e "ssh -q -p $port" $user@$server:$target_folder
    echo -e "$cl_lcyan[CSSHS]$cl_cyan Sync completed on $(date), the next sync will happen $(date -d "$sec seconds")$cl_clear"
		sleep 1
	  echo -e "$cl_lcyan[CSSHS]$cl_cyan Waiting $sec seconds$cl_clear"
		sleep $sec
		ping_check
		sync
  }

default_command="rsync --prune-empty-dirs --update --no-motd --progress --human-readable --preallocate --stats --delete-before -r"
echo -e "$cl_darkred############################################$cl_clear"
echo -e "$cl_darkred#             Cloud SSH Sync               #$cl_clear"
echo -e "$cl_darkred# Secure Shell synchronisation utility     #$cl_clear"
echo -e "$cl_darkred# Author: headless_cyborg                  #$cl_clear"
echo -e "$cl_darkred# Version: 0.6                             #$cl_clear"
echo -e "$cl_darkred# Dev branch: f                            #$cl_clear"
echo -e "$cl_darkred############################################$cl_clear"
# NOTE: Do not use experimental ('e') branch version if you don't have a backup of your files
	echo -e ""
  anti-root_check
  config_file_check
  sync_folder_check
  ping_check
  sync
# SERVER CONFIG
server="192.168.10.199"
port="25585"
user="server"
sec=14400

# SYNCHRONISATION CONFIG
sync_folders=("/home/hdlscbrg/Dokumenty" "/home/hdlscbrg/Obrázky" "/home/hdlscbrg/Stažené" "/home/hdlscbrg/Hudba" "/home/hdlscbrg/Videa")
target_folder="/mnt/disk2"

Benewatch

Jazyk: Bash
Účel: Kontrolovat teplotu na Benekov kotli, kterou poskytuje zabudovaná jednotka Siemens přes HTTP a při překročení dané teploty odeslat upozorňující e-mail

#####################################################################

# INTERNAL VARIABLES
monitored_temperature=91
address="192.168.10.100"
username="ADMIN"
password=""
time=800

# E-MAIL VARIABLES
recipient=""

function monitoring ()
{
if ping -c 1 ${address} &> /dev/null
then
  echo "Ping OK"
else
  echo "[BENEWATCH]: Warning - server ping failed" | mail -s "Benewatch" $recipient
fi
wget --recursive -q --user $username --password $password http://$address/HMI00001.cgi -P ~/.local/share/benewatch/
temperature="$(cat ~/.local/share/benewatch/$address/HMI00001.cgi | sed '115q;d' | sed 's/[^0-9]*//g')"
#temperature_raw="${temperature:0:${#temperature}-6}"
#temperature_raw="${${temperature} | sed 's/......$//'}"
echo $temperature
if [ "$temperature" -gt "$monitored_temperature" ]
then
echo "[BENEWATCH] Boiler temperature is higher than monitored temperature (monitored = $monitored_temperature °C, current = $temperature °C)"
echo "[BENEWATCH]: Boiler temperature too high ($temperature °C)" | mail -s "[BENEWATCH] Boiler temperature" $recipient
echo "[BENEWATCH] Sending e-mails"
echo "[BENEWATCH] Waiting $time seconds for the next temperature check"
sleep $time
echo "[BENEWATCH] Starting monitoring"
sleep 1
monitoring
fi
echo "[BENEWATCH] Boiler temperature is ok (${temperature} °C), monitored temperature (${monitored_temperature} °C) was not exceeded"
echo "[BENEWATCH] Waiting $time seconds for the next temperature check"
sleep $time
echo "[BENEWATCH] Starting monitoring"
sleep 1
monitoring
}
echo "[BENEWATCH] Monitoring started"
sleep 1
echo "[BENEWATCH] Temperature treshold set to ${monitored_temperature} °C"
sleep 1
echo "[BENEWATCH] Starting monitoring"
sleep 1
monitoring

Convert

Jazyk: Bash
Účel: Udělátko na konvertování videa