varnish debug cheat sheet

Varnish cheat sheet Intro How to see caching stats etc. Varnish show hitratio rate varnishstat Hitrate ratio: 10 100 1000 Hitrate avg: 0.3373 0.3012 0.3400 This Means the last 10 seconds we have a hitrate of 33.73% and the last 100 seconds only 30.12% show urls missed varnishlog -m “VCL_call:miss” | grep –line-buffered “RxURL” work in progress, because it’s my cheat sheet Richard
One minute to read

tmux cheat sheet

Tmux cheat sheet Intro I am trying to use tmux more than screen, but a cheat sheet could be usefull. Quick and dirty tmux detach from window ctrl-b d list sessions tmux ls connect to session tmux at -t create session tmux new -s “session_name” “command” create detached sessioni tmux new -d Extra info split window in multiple pane split horizontal ==== ctrl-b " split vertical || ctrl-b % move to other pane ctrl-b cursor-key-direction
One minute to read

Split a mysql dump in databases

Hello, I once needed to split a mysql dump in to multiple files, one per database so i used this awk one liner. awk -F'`' '{if ($0 ~ /^– Current Database:/) db=$2; print >> db"-split.sql"}' mysql_dump.sql If you need to split one table from one database you can try the following bash scripts !/bin/bash export DATABASE="$1" export TABLE="$2" echo $DATABASE echo $TABLE awk '/Table structure for table .'$TABLE'.$/,/UNLOCK TABLES/{print}' $DATABASE-split.sql
One minute to read

reattach ssh or script to new tty

Once in a will you need you have a lang running script that you started into a shell but you want to transfer it to a screen. For this i am using the reptyr program which i installed with sudo pacman -S reptyr or sudo apt-get install reptyr find pid ps ax | grep ssh # find pid 34177 (for example) # start a screen screen -S my_screen_name # in de screen start reptyr reptyr 34177 if you get a issue with ptrace scope just change this value echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
One minute to read

Screen or Daemontools

If you want to start some daemon in the background you can install daemontools and user supervise, but i like to use screen to start daemons in the background, so that i can easily see the output.

check screen if ! /usr/bin/screen -ls | awk '{print $1}' | grep ".${SCREEN_NAME}$" >/dev/null; then echo "starting $SCREEN_NAME" screen -S "${SCREEN_NAME}" -d -m "$COMMAND_SCRIPT" fi I use this snippet, to check of a screen with a given name exists and if not start it up, i run a script i call screen-ls.

4 minutes to read

bash locking in script

Bash locking Intro Once in a while i want to start a bash script and make sure it one at a time. So searching for solution for creating a lock file in bash, you want to have a solution that doesn’t create a race condition. Explanation Start defining which lockfile you want to use export lockfile=/tmp/lockfile.txt Get pid from lockfile, return empty string if file doesn’t exists or is empty For added protection removed character from the file that isn’t a number
3 minutes to read

bash debugging tricks i forget all the time

Bash debugging Introduction Once in a while i need to debug a bash script that i wrote, but i need to search how to get the line number of debug to a file, so easier for me to put it in mij blog, maybe it will help somebody else also. Howto Enable debugging set -x Add line numbers PS4=’$LINENO: ' Debug to external file exec 5> debug_output.txt BASH_XTRACEFD="5" PS4='$LINENO: ' set -x Disable debug
One minute to read