Skip to content

Instantly share code, notes, and snippets.

View rojenzaman's full-sized avatar
🏴
Why?

Rojen Zaman rojenzaman

🏴
Why?
  • localhost
  • Istanbul, Turkey
  • 05:16 (UTC +03:00)
View GitHub Profile
@rojenzaman
rojenzaman / emerg_open_error.sh
Created February 5, 2022 09:29
Solve: nginx: [emerg] open() error
mkdir -vp $(dirname "$(nginx -t |& grep '\[emerg\]' | awk '{print $4}' | sed 's/"//g')")
@rojenzaman
rojenzaman / merge_nginx_logrotated.sh
Last active January 16, 2022 08:46
Bash script to merge NGINX logrotate files.
#!/bin/bash
print_cron_rules() { echo "ClNFVCBDUk9OVEFCOgoKQGhvdXJseSAvdXNyL2Jpbi9tZXJnZV9uZ2lueF9sb2dyb3RhdGVkLnNoIC92YXIvbG9nL25naW54IGhvdXIKQGRhaWx5IC91c3IvYmluL21lcmdlX25naW54X2xvZ3JvdGF0ZWQuc2ggL3Zhci9sb2cvbmdpbnggZGF5CkB3ZWVrbHkgL3Vzci9iaW4vbWVyZ2VfbmdpbnhfbG9ncm90YXRlZC5zaCAvdmFyL2xvZy9uZ2lueCB3ZWVrCkBtb250aGx5IC91c3IvYmluL21lcmdlX25naW54X2xvZ3JvdGF0ZWQuc2ggL3Zhci9sb2cvbmdpbnggbW9udGgKCg==" | base64 -d; }
usage() { echo "Usage: ${BASH_SOURCE[0]} [DIR] [ hour | day | week | month ] <error>"; print_cron_rules; exit 1; } ; if [[ "$#" -lt 1 ]]; then usage; fi
DIR="$(realpath "${1}")"
TIME="${2:-hour}"
ERROR_LOG="${3:-false}"
ZSTD_LEVEL="19"
MERGE_ROTATED_LOCKFILE="/tmp/MERGE_ROTATED_IS_RUNNING.${TIME}.lock"
hour() { date +hour.%d-%m-%Y_%Hh%Mm%Ss.%A ; }
day() { date +day.%d-%m-%Y_%Hh%Mm.%A ; }
@rojenzaman
rojenzaman / count_ip.sh
Created August 11, 2021 18:22
Count IP address in Nginx access logs
#!/bin/bash
if [ "$#" -lt 1 ]; then
echo "Usage: `basename $0` <access.log>"
exit 1
fi
awk '{print $1}' "${1}" | sort | uniq -c | sort -nr
@rojenzaman
rojenzaman / parse-url.sh
Created July 16, 2021 14:23
Parse URL in bash script
#!/bin/bash
#SOURCE: https://janikvonrotz.ch/2021/03/09/parse-url-in-shell-script/
set -e
# Get script name
SCRIPT=$(basename "$0")
# Display Help
Help() {
@rojenzaman
rojenzaman / date.txt
Last active July 13, 2021 12:29
date command: W3C "complete date plus hours, minutes and seconds" format
date +"%Y-%m-%dT%H:%M:%S%:z"
@rojenzaman
rojenzaman / systemctl
Created July 1, 2021 19:21
Emulate systemctl for runit installed termux
#!/bin/bash
# Emulate systemctl for runit installed termux.
function check_command() { [ -x "$(command -v ${1})" ] || { echo -e "\e[31m${1} not found, please install it.\e[0m" ; return 1 ; } }
if ! check_command sv; then
if ! check_command sv-enable; then
if ! check_command sv-disable; then
exit 1
fi
@rojenzaman
rojenzaman / telegram-send.sh
Created June 30, 2021 10:35
Send mp3 files via telegram with checking their hashsums.
#!/bin/bash
cd "$(dirname "${BASH_SOURCE[0]}")"
LIST=".nosend"
[ -f ${LIST} ] || touch ${LIST}
shopt -s expand_aliases
SLEEP="2"
USAGE="--send | --dry"
function check_command() { [ -x "$(command -v ${1})" ] || { echo -e "\e[31m${1} not found, please install it.\e[0m" ; return 1 ; } }
@rojenzaman
rojenzaman / docker-compose-stats.sh
Created June 24, 2021 12:49
docker-compose stats
#!/bin/bash
# stats function to docker-compose
docker-compose ps -q | xargs docker stats
@rojenzaman
rojenzaman / dynmotd.sh
Last active March 9, 2025 14:20
Rocky Linux dynamic motd
#!/bin/bash
# Installation:
#
# 1. nano /etc/ssh/sshd_config
# PrintMotd no
#
# 2. nano /etc/profile
# /usr/bin/dynmotd # Place at the bottom
#
@rojenzaman
rojenzaman / get_port.sh
Last active September 3, 2024 12:13
Get an unused port.
#!/bin/bash
read LOWERPORT UPPERPORT < /proc/sys/net/ipv4/ip_local_port_range
while :
do
PORT="`shuf -i $LOWERPORT-$UPPERPORT -n 1`"
ss -lpn | grep -q ":$PORT " || break
done
echo $PORT