How to find out where exactly the packet is being lost
It’s a pretty common occurrence when you have 2 hosts pinging each other and some packets are being lost. And sometimes you need to make sure, that the routing device […]
It’s a pretty common occurrence when you have 2 hosts pinging each other and some packets are being lost. And sometimes you need to make sure, that the routing device […]
Here’s a short and pretty self-desctriptive recipe to make your Postfix to send outgoing messages from different IP-addresses switching them on a round-robin basis. First of all, we’ll need the […]
This simple script lists today’s tasks every time you log in (or create a new window in your screen).
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49  | 
						# 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) function toDay() {         local DAY=${1};  shift;         local CARD=${1}; shift;         local TODO=${*}         (                 if [ ! -d "${TODAYD}/${DAY}" ]; then                         mkdir -p "${TODAYD}/${DAY}"                 fi         ) && (                 echo "${TODO} [+${TODAY}]" >> "${TODAYD}/${DAY}/${CARD}"         ) && (                 echo -n "${TODAYD}/${DAY}/${CARD}: "                 cat "${TODAYD}/${DAY}/${CARD}"         ) } echo -n -e "Today is \033[0;36m$(date +%A)\033[0m, \033[0;35m${TODAY}\033[0m" if [ -d "${TODAYD}/${TODAY}" ] && STUFF=$(ls "${TODAYD}/${TODAY}") && [ -n "${STUFF}" ]; then         for CARD in ${STUFF}; do                 (cat "${TODAYD}/${TODAY}/${CARD}" >> "$TODAYD/today/${CARD}") &&                         rm -f "${TODAYD}/${TODAY}/${CARD}"         done         rmdir "${TODAYD}/${TODAY}" fi if [ -d "${TODAYD}/today" ] && STUFF=$(ls -X "${TODAYD}/today/") && [ -n "${STUFF}" ]; then         echo \ and here\'s what to do:         for CARD in ${STUFF}; do                 echo -n -e " * \033[1;33m(\033[1;37m${CARD}\033[1;33m)\033[0m "                 cat "${TODAYD}/today/${CARD}"         done         echo Good luck! else         echo , don\'t you know what to do? =\) fi echo  | 
					
Adding a new task is as easy as typing something […]
Sometimes you need to shut some web-services down for a while to do some maintenance works. Of course, you have warned all users about the scheduled downtime period, but what […]
Sometimes you have to check if some host replies on ARP “who-has” requests instead of simply pinging it. You probably need it when the host has its firewall configured to […]
This post’s name and script’s comments are pretty descriptive, right? 🙂
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67  | 
						#!/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 OPTS=$(getopt -n $(basename ${0}) -o 1:5:f:s:kp: -l la1:,la5:,laf:,service:,kill,process: -- "${@}") if [ "${?}" -ne 0 ]; then         echo "Can't get options" >&2         exit 1 fi eval set -- "${OPTS}" while :; do         case "${1}" in                 -1|--la1)                         THR1="${2}"; shift 2;;                 -5|--la5)                         THR5="${2}"; shift 2;;                 -f|--laf)                         THR15="${2}"; shift 2;;                 -s|--service)                         SERVICE="${2}"; shift 2;;                 -k|--kill)                         KILL="1"; shift 1;;                 -p|--process)                         PROCESS="${2}"; shift 2;;                 --)                         shift; break;;                 *)                         echo "Can't recognize the option: ${1}"; exit 1;;         esac done if [ -z "${SERVICE}" ]; then         echo "Can't understand what service shall I restart" >&2         exit 1 fi if [ "${KILL}" ] && [ -z "${PROCESS}" ]; then         echo "Can't understand what process shall I kill" >&2         exit 1 fi LA=$(  uptime | sed -r 's/^.*load average: ([0-9]+)(\.[0-9]+)?, ([0-9]+)(\.[0-9]+)?, ([0-9]+)(\.[0-9]+)?$/\1\t\3\t\5/g' ) LA1=$( echo "${LA}" | cut -f1) LA5=$( echo "${LA}" | cut -f2) LA15=$(echo "${LA}" | cut -f3) if         [ -n "${THR1}"  ] && [ -n "${LA1}"  ] && [ "${LA1}"  -ge "${THR1}"  ] &&         [ -n "${THR5}"  ] && [ -n "${LA5}"  ] && [ "${LA5}"  -ge "${THR5}"  ] &&         [ -n "${THR15}" ] && [ -n "${LA15}" ] && [ "${LA15}" -ge "${THR15}" ]; then         if [ "${KILL}" ]; then                 while PIDS=$(pidof ${PROCESS}); do                         echo "Slaying ${PIDS}..."                         kill -9 ${PIDS}                         sleep 1                 done                 sleep 10         else                 service "${SERVICE}" restart         fi fi  | 
					
Of course, you can get all further updates of this script from GitHub: https://gist.github.com/melnik13/04225e4e60a8d66f9ab6. Now you can sleep […]
Wouldn’t it be lovely if you could run some command on a bunch of servers? Of course, you can! Most of us would do something like that:
| 
					 1  | 
						for HOST in host1 host2 host3; do { ssh "${HOST}" "echo ZALOOPA > /var/tmp/zaloopa"; } done  | 
					
But what […]
If you ever needed a tool to get to know which files are growing faster than other ones, you probably will be quite satisfied with this simple bash-script.
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58  | 
						#!/bin/sh # Checking the spool directory SPOOL=/var/spool/diskhogs if [ ! -e "${SPOOL}" ]; then         mkdir -p "${SPOOL}" fi if [ ! -d "${SPOOL}" ]; then         echo "There are no ${SPOOL} directory" >&2         exit 1 fi if [ -z "${1}" ]; then         DIR=. else         DIR="${1}" fi FILES=$(find "${DIR}" -type f) TIME=$(date +%s) if [ -z "${TIME}" ]; then         echo "Can't determine current time" >&2         exit 1 fi for FILE in ${FILES}; do         SIZE=$(ls -nl ${FILE} | awk '{ print $5 }')         if [ -z "${SIZE}" ]; then                 echo "Can't determine size of the ${FILE} file" >&2                 continue         fi         sqlite3 "${SPOOL}/db" "INSERT INTO sizes VALUES ('${FILE}', '${TIME}', '${SIZE}');"         if [ ${?} -ne 0 ]; then                 continue         fi done for PERIOD in 60 300 600 1800 3600 86400; do         TIME_WAS=$((${TIME} - ${PERIOD}))         (                 echo "*** Since $(date --date="@${TIME_WAS}") (${PERIOD} seconds ago) ***"                 sqlite3 \                         "${SPOOL}/db" \                         "SELECT MAX(size) - MIN(size) AS mm, name                                 FROM sizes                                 WHERE time >= '${TIME_WAS}'                                 GROUP BY name                                 ORDER BY mm                         ;"         ) > "${SPOOL}/report_${PERIOD}" done  | 
					
Simply […]