Skip to content

Instantly share code, notes, and snippets.

View stoyanovgeorge's full-sized avatar
🎯
Focusing

Georgi Stoyanov stoyanovgeorge

🎯
Focusing
  • Techtriq GmbH
  • Germany
View GitHub Profile
@stoyanovgeorge
stoyanovgeorge / random_number_range.sh
Last active August 20, 2018 10:46
Bash script which generates random number in a range [0 : 500]
#!/bin/bash
range=500
number=$RANDOM
let "number %= $range"
printf "Random number less than %s - %s\n" "$range" "$number"
@stoyanovgeorge
stoyanovgeorge / ping_check.sh
Last active August 20, 2018 10:46
Check whether a host is replying to ICMP requests or not. Usage: ./script.sh 192.168.1.1
#!/bin/bash
# check if the $1 is empty
if [[ -z "$1" ]];then
printf "Please define the IP or the hostname which you want to check!\nUsage: ./script.sh 192.168.1.1\n"
else
if ping -c 1 "$1" &> /dev/null;then
printf "%s is UP!\n" "$1"
else
printf "%s is DOWN!\n" "$1"
@stoyanovgeorge
stoyanovgeorge / var_integer.sh
Last active August 20, 2018 10:45
Check if $var is integer or not
#!/bin/bash
if [[ "$var" =~ ^-?[0-9]+$ ]];then
echo "integer"
else
echo "not integer"
fi
@stoyanovgeorge
stoyanovgeorge / md5sum_unique_finder
Created August 20, 2018 09:56
Find the unique files in a directory using md5sum
md5sum * | sort -k1 | uniq -w 32 -d
@stoyanovgeorge
stoyanovgeorge / md5sum_duplicates_remover.sh
Last active August 20, 2018 10:45
Backup files from $HOME/backup directory and
#!/bin/bash
bkp_dir="$HOME/backup"
now="$(date +'%Y%m%d')"
tar cfJ $HOME/backup/"${now}"_scripts.tar.xz "$HOME"/scripts/ &> /dev/null
# Evaluates the md5sum of the most recent backup and compares its md5sum against the other files in the same directory. If the md5sum is the same removes the duplicated file
md5sum_now=$(md5sum "$bkp_dir"/"${now}"_scripts.tar.xz | awk '{ print $1 }')
@stoyanovgeorge
stoyanovgeorge / mc_routing.sh
Last active July 17, 2019 12:52
Creates a multicast routing after the user inputs a valid network interface and then it lists the routing table.
#!/bin/bash
# Creating an array containing all network interfaces which are up
net_array=()
for iface in $(ifconfig | cut -d ' ' -f1| tr ':' '\n' | awk NF)
do
net_array+=("$iface")
done
unset "net_array[${#net_array[@]}-1]"
@stoyanovgeorge
stoyanovgeorge / ffmpeg_stream_check.ts
Last active January 3, 2022 16:40
Records 10 seconds of an UDP multicast stream and then it shows the stream settings using mediainfo. Requires medianfo and ffmpeg installed on the host
#!/bin/bash
stream=""
recording_dir=$HOME/recordings
while [[ ! $stream =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9] ]];
do
echo "Please enter a valid multicast address and port in the format: IP.AD.DR.ESS:PORT after the script name!"
read -r stream
done
@stoyanovgeorge
stoyanovgeorge / backup.sh
Created August 30, 2018 11:46
Backup script which will backup all the files in a custom directory, will create a tar.xz archive and will delete previous backup files in case the md5sum is the same.
#!/bin/bash
target_dir=""
bkp_dir=""
while [[ ! $bkp_dir =~ [a-zA-Z] && ! -d "$bkp_dir" ]];
do
echo "Please enter a valid directory to backup:"
read -r bkp_dir
done
#!/bin/bash
n='([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
m='([0-9]|[12][0-9]|3[012])'
IFS= read -rp 'Input: ' ipaddr
if [[ $ipaddr =~ ^$n(\.$n){3}/$m$ ]]; then
printf '"%s" is a valid CIDR\n' "$ipaddr"
elif [[ $ipaddr =~ ^$n(\.$n){3}$ ]]; then
@stoyanovgeorge
stoyanovgeorge / psnr_check.sh
Created October 23, 2018 12:39
Compares two image files and returns the PSNR and MSE values.
#!/bin/bash
if [ -e "$1" ] && [ -e "$2" ];
then
if file "$1" | grep -qE 'image|bitmap' && file "$2" | grep -qE 'image|bitmap' ;
then
ffmpeg -loglevel error -i "$1" -i "$2" -lavfi psnr=psnr.log -f null -
cat psnr.log
rm psnr.log
else