Skip to content

Instantly share code, notes, and snippets.

View khmarochos's full-sized avatar
🇺🇦
Слава Україні!

Volodymyr Melnyk khmarochos

🇺🇦
Слава Україні!
View GitHub Profile
for dir in $(find /export/secondary2/snapshots -wholename '/export/secondary2/snapshots/*/*' -type d); do { files=$(ls "${dir}" | wc -l); if [[ "${files}" -gt 2 ]]; then echo $dir; ls -tl "${dir}"; for file in $(ls -t "${dir}" | tail --lines +3); do { read -p "Remove ${file}?" -n 1 -r; if [[ "${REPLY}" =~ ^[Yy]$ ]]; then echo " ... removing ${dir}/${file}"; rm "${dir}/${file}"; else echo " ... skipping ${dir}/${file}"; fi; } done; fi; } done
for dir in $(find /export/secondary2/snapshots -wholename '/export/secondary2/snapshots/*/*' -type d -mtime +21); do { if [[ "$(ls ${dir} | wc -l)" -lt 1 ]]; then continue; fi; ls -tl "${dir}"; read -p "Remove ${dir}?" -n 1 -r; if [[ "${REPLY}" =~ ^[Yy]$ ]]; then echo " ... removing ${dir}"; rm -rf "${dir}"; else echo " ... skipping ${dir}"; fi; } done
#!/bin/sh
PATH=/bin:/usr/bin
HOME=~
HOSTNAME=$(hostname)
USER=$(echo "${HOSTNAME}" | sed "s/\.tucha13\.net$//")
INCLUDES="/etc/rsync-backup.includes"
EXCLUDES="/etc/rsync-backup.excludes"
BSERVERADDR="backup.z2.tucha13.net"
BSERVERPORT="22"
#!/usr/bin/env perl
#
# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=perl
#
use strict;
use warnings;
use DBI;
#!/bin/bash
function log {
echo "[$(date +%F\ %T)]" $* >&2
}
function warn {
log "[!]" $*
}
@khmarochos
khmarochos / sockping.sh
Last active December 29, 2021 10:25
To establish a TCP-connection and be keeping it alive
#!/bin/bash
function log {
echo $(date) ' >> ' $* >&2
}
function die {
echo $* >&2
exit 1
}
@khmarochos
khmarochos / pingmon.sh
Last active April 16, 2016 07:43
Ping the Host and Trace the Route
TARGET=13.13.13.13; while :; do { PL=$(ping -c 10 -W 1 "${TARGET}" | sed -n -r 's/^.+ ([0-9]{1,3})% packet loss.+/\1/gp'); if [[ "${PL}" -gt 25 ]]; then { echo "$(date): ${PL}% of requests haven't got any responses"; mtr -i 0.1 -r -c 10 "${TARGET}"; echo; } fi; } done
#!/bin/bash
CODE_OK=0
CODE_UNKNOWN=1
CODE_WARNING=2
CODE_CRITICAL=3
WARNING_THRESHOLD="80%"
CRITICAL_THRESHOLD="100%"
DEBUG=0
@khmarochos
khmarochos / pingtrace.sh
Last active September 29, 2015 07:29
When you can't install the mtr utility, but need to determine on which hop your datagrams are being lost
#/bin/bash
HST="8.8.8.8"
CNT="100"
DIR="$(mktemp -d /tmp/ping_XXXXXXXX)"
echo "Results will be stored to the ${DIR} directory"
for HOP in $(traceroute -n "${HST}" | sed -nr 's/^[[:space:]]*([[:digit:]]+)[[:space:]]+([[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3})[[:space:]]+.*$/\1:\2/gp'); do
IFS_OLD="${IFS}"; IFS=":"; read -a ARR <<< "${HOP}"; IFS="${IFS_OLD}"
@khmarochos
khmarochos / .bash_today
Last active June 22, 2021 06:36
.bash_today: This simple script lists today’s tasks every time you log in (or create a new window in your screen)
# Just add me to your .bashrc:
# [ -x ~/.bashrc_today ] && . ~/.bashrc_today
TODAYD="${HOME}/.today.d"
if [ ! -d "${TODAYD}/today" ]; then
mkdir -p "${TODAYD}/today"
fi
TODAY=$(date +%F)
@khmarochos
khmarochos / aarping.sh
Last active August 29, 2015 14:15
Need to check some host's availability by arping, but have no time to look up which network intrface you need? aarping.sh is here to help you.
#!/bin/sh
if [ -z "${1}" ]; then
echo "Chocho?" >&2
exit 1
fi
HOSTIP="${@: -1}"
ROUTE=$(ip route get "${HOSTIP}")