Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍👩‍👦
I might be slow on response, as my newborn child consumes all the free time :-)

Volodymyr Melnyk melnik13

👨‍👩‍👦
I might be slow on response, as my newborn child consumes all the free time :-)
View GitHub Profile
@melnik13
melnik13 / update-serial.pl
Created Jul 2, 2014
This script updates the serial attribute of your bind's zone files
View update-serial.pl
#!/usr/bin/perl -p -i*.bak
use strict;
use POSIX qw(strftime);
if(/^\s+(\d{10,})\s*;\s+serial/i) {
my $serial = strftime("%Y%m%d00", localtime);
$serial++ while($serial <= $1);
s/$1/$serial/;
@melnik13
melnik13 / check_ipmi.sh
Created Sep 4, 2014
check_impi.sh - a Nagios plugin for checking IPMI availability
View check_ipmi.sh
#!/bin/sh
OPTS=$(getopt -n "${PROGNAME}" -o H: -- "${@}")
if [ "${?}" -ne 0 ]; then
say 1 $(usage "${PROGNAME}")
die "Can't get options"
fi
eval set -- "${OPTS}"
while :; do
case "${1}" in
View gist:02de9642e33a824d76a6
#!/usr/bin/env perl
use strict;
use warnings;
use POSIX;
my $field_original = <<__FIELD__
.* .
. .
. .
@melnik13
melnik13 / lalala.sh
Last active Aug 29, 2015
A quick and dirty cronjob to reset some service whel LA raises way too high
View lalala.sh
#!/bin/bash
#
# Just put it to your crontab:
#
# * * * * * root /root/bin/lalala.sh --la1 50 --la5 20 --laf 10 --service httpd --kill --process httpd
#
# It will kill all httpd processes and restart httpd service when LA1 becomes greater or equal to 50, LA5 - to 20 and LA15 - to 10
#
PATH=/bin:/sbin:/usr/bin
@melnik13
melnik13 / aarping.sh
Last active Aug 29, 2015
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.
View aarping.sh
#!/bin/sh
if [ -z "${1}" ]; then
echo "Chocho?" >&2
exit 1
fi
HOSTIP="${@: -1}"
ROUTE=$(ip route get "${HOSTIP}")
@melnik13
melnik13 / pingtrace.sh
Last active Sep 29, 2015
When you can't install the mtr utility, but need to determine on which hop your datagrams are being lost
View pingtrace.sh
#/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}"
View check_sensors.sh
#!/bin/bash
CODE_OK=0
CODE_UNKNOWN=1
CODE_WARNING=2
CODE_CRITICAL=3
WARNING_THRESHOLD="80%"
CRITICAL_THRESHOLD="100%"
DEBUG=0
@melnik13
melnik13 / pingmon.sh
Last active Apr 16, 2016
Ping the Host and Trace the Route
View pingmon.sh
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
@melnik13
melnik13 / .bashrc
Last active Apr 26, 2016
Cool functions for your ~/.bashrc
View .bashrc
# This function allows you to "seed" the remote host by your RSA public key:
seed() { ssh "${1}" "umask 077; test -d ~/.ssh || mkdir ~/.ssh ; echo '$(< ~/.ssh/id_rsa.pub)' >> ~/.ssh/authorized_keys" ; }
# This function allows you to change owner and group attributes of all files in the
# desired directory making them equal to corresponding attributes of this directory:
own() { [ -n "${1}" ] && [ -d "${1}" ] && chown -R $(ls -al --time-style=+%s | sed -rn 's/^[^[:space:]]{10,}[[:space:]]+[[:digit:]]+[[:space:]]+([^[:space:]]+)[[:space:]]+([^[:space:]]+)[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+\.$/\1:\2/p') "${1}"; }
# Dumps traffic either to the file and stdout
tcpdumplog() { DDIR="/tmp/dumps/$(date +%F)/${1}" ; [[ -d "${DDIR}" ]] || mkdir -p "${DDIR}" ; tcpdump -i "${1}" -e "${2}" -s 65535 -w - | pv | tee "${DDIR}/' ${2} '.dump" | tcpdump -n -r -; }
View mtr-mon.sh
#!/bin/bash
function log {
echo "[$(date +%F\ %T)]" $* >&2
}
function warn {
log "[!]" $*
}