Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

George Stoyanov stoyanovgeorge

🎯
Focusing
Block or report user

Report or block stoyanovgeorge

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stoyanovgeorge
stoyanovgeorge / cpu_usage.sh
Created Aug 21, 2019
Print the total CPU usage in the terminal and updates its value every second.
View cpu_usage.sh
#!/bin/bash
# Created by Paul Colby (http://colby.id.au)
# Further edited by Georgi Stoyanov (http://gstoyanov.com), no rights reserved ;)
PREV_TOTAL=0
PREV_IDLE=0
# Determinining the number of CPU cores
CPU_CORES=$(nproc --all)
@stoyanovgeorge
stoyanovgeorge / mc_join
Created Jul 17, 2019
Join Multicast addresses over IGMP
View mc_join
The join command requires smcroute package to be installed
You can install it by executing:
sudo apt install smcroute
sudo smcroutectl join <interface> <mc_address>
where:
1. <interface> is the interface on which the MC traffic should be present
@stoyanovgeorge
stoyanovgeorge / avg_speed.sh
Last active Apr 15, 2019
An one line command to get the average RX and TX speed of a particular interface (eth0) over $INT seconds in bytes per second. You need to divide by 128 to get it in Kbps or by 131072 (128*1024) for Mbps.
View avg_speed.sh
#!/bin/bash
INT=2; RXDIR=/sys/class/net/eth0/statistics/rx_bytes; TXDIR=/sys/class/net/eth0/statistics/tx_bytes; RXSTART=$(cat $RXDIR); TXSTART=$(cat $TXDIR); sleep $INT; RXEND=$(cat $RXDIR); TXEND=$(cat $TXDIR); RXBPS="$(((RXEND-RXSTART)/INT))"; TXBPS="$(((TXEND-TXSTART)/INT))"; echo "$RXBPS" "$TXBPS"
@stoyanovgeorge
stoyanovgeorge / process_checker.sh
Created Mar 27, 2019
Checks and records in a CSV file how many processes with a <process_name> are running every 10 seconds.
View process_checker.sh
#!/usr/bin/env python3
import subprocess
import csv
import os
import time
from datetime import datetime
from pathlib import Path
#### Variables definition
@stoyanovgeorge
stoyanovgeorge / proc_monitor.sh
Created Feb 15, 2019
Python3 script monitoring if a process is running and logging the time when the process has stopped. It works for one or multiple instances of the same process.
View proc_monitor.sh
#!/usr/bin/env python3
''' Script checking if a pre-defined process is running '''
import subprocess
import shlex
import time
import datetime
import psutil
import os
@stoyanovgeorge
stoyanovgeorge / sshd_config
Created Feb 15, 2019
Hardened SSH configuration file for modern Linux servers
View sshd_config
# $OpenBSD: sshd_config,v 1.102 2018/02/16 02:32:40 djm Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
@stoyanovgeorge
stoyanovgeorge / check_running_status.sh
Created Feb 11, 2019
Check if a PID (process ID is running and return True in case it does.
View check_running_status.sh
#!/bin/bash
if [[ $(ps -o pid= -p 2310) -ne 0 ]]; then
echo "True"
else
echo "False"
fi
@stoyanovgeorge
stoyanovgeorge / psnr_check.sh
Created Oct 23, 2018
Compares two image files and returns the PSNR and MSE values.
View psnr_check.sh
#!/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
View check_ip.sh
#!/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 / backup.sh
Created Aug 30, 2018
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.
View backup.sh
#!/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
You can’t perform that action at this time.