## Simple solutions Solène Rapenne BitreichCON 2019 ## About me + Sysadmin since 2011 + Managing FreeBSD hosts for a living + Member of OpenBSD project since 2018 ## SIMPLE SOLUTIONS + Simple tools + Makefile + Drist + Crontab + Tips ## Simple tools + know your shell (tests, loops, special variables, limitations) + find / awk / grep + reuse data + have fun and optimize later + learn AWK ## Simple tools examples + using curl+AWK for making a RSS file from https://www.openbsd.org/faq/current.html + bitreich lawn status ## Have fun example #1 Building a small gopher client 1. Fetch data printf "/\n" | nc bitreich.org 2. Only display actual text | cut -d ' ' -f 1 3. Display "i" fields without i and indent others types awk '{ if(substr($0,0,1)=="i") { print substr($0,2) } else { printf "\t%s\n", $0 }}' ## Have fun example #2 part 1 Extract article titles from my blog 1. Fetch data curl https://dataswamp.org/~solene/index.html Titles are within a a tag and link is relative and starts with a date. Output is html 2. Filter on the previous pattern detected | grep "Git cheat sheet

How to send html signature in mu4e

My Stumpwm config on OpenBSD

Port of the week: mbuffer

FreeBSD 11 and Perc H720P Mini raid controller

## Have fun example #2 part 2 3. Separate content from tags It's easier to work on lines | tr '<>' '\n' Output looks like: h1 a href="2016-05-02-3.html" How to add a route through a specific interface on FreeBSD 10 /a /h1 4. Get line after a "a href" | awk '/^a href/ { getline; print}' Output: My Stumpwm config on OpenBSD Port of the week: mbuffer FreeBSD 11 and Perc H720P Mini raid controller Port of the week: rdesktop ## Learn AWK + available everywhere + sed / grep / cut / tr all in one + Print penultiem field awk '{ print $(NF-1) }' + Reorder fields awk '{ print $3" "$2 }' + Extensible (contrary to a combination of sed / grep / cut) + Avoid writing it as one liner! ## Makefile + Idea from bitreich + Standard interface + Use it everywhere + Stop on error + Replacement for scripts? ## Drist + simple of use + super fast + but not perfect + awesome with makefile! ## Drist tips + Install package if not present ls /usr/local/bin/nginx || pkg install -y nginx + Add a line at the end of line (ONCE) grep ^md99 /etc/fstab || \ ( echo "md99 none swap sw,file=/swap.disk 0 0" >> /etc/fstab ) + Add a line at a specific place FILE=/usr/local/etc/lighttpd/modules.conf PATTERN=\"mod_openssl\" grep "$PATTERN" "${FILE}" || ( printf '%s\n' 1a ' "${PATTERN},' . w | ed $FILE ) + Fetch remote data into the drist directory rsync -aRv remote:/home/solene/.ssh/ files/ ## Crontab + available everywhere + run your scripts while having fun + have some kind of output (mail or file) + I solved it lacks of automation with awk gopher://dataswamp.org/0/~solene/article-crontab-manipulation.txt https://dataswamp.org/~solene/2018-05-31-crontab-manipulation.html This includes a text file within defined tags (in comment) within crontab and replace the content on each run. ## Tips + Write everything you do Store most of your work, you may need it later + Track file history with a version control system Keep track of every versions of your files. + Handling Failing script command || ( echo failure | mail solene ) + Checking changes between runs command_something > new diff -u old new > diff if [ -s diff ]; then do something it changed! ; fi mv new old