1984 – the techblog

(Hopefully) useful various sysadmin and other stuff.


BSD watch (or: poor man’s GNU watch)

On GNU, there’s a neat com­mand to keep an eye on arbi­trary com­mands. It’s very use­ful when a fel­low sysad­min needs to mon­i­tor some­thing else than log files, or trace bina­ries. Naïve as I am, I tried to use this on a FreeBSD sys­tem as well, only to dis­cover that the default watch com­mand does […]

Bash: Handling various versions of wc

I really love the wc tool. For those who don’t know it, it sim­ply counts words, lines, char­ac­ters and bytes of any input it receives on STDIN. You’d be sur­prised how often one needs this func­tion­al­ity! But, as with many things POSIX/UNIX, there are dif­fer­ent flavours avail­able; while many tools have the same name on all […]

Get the sum of a column in shell (using awk) or: find out cumulative memory consumption

The title already gives it already away, awk is the tool to use here: awk ‘{ SUM += $YOUR_FIELDNUMBER} END { print SUM }’ where YOUR_FIELDNUMBER is the num­ber of the col­umn you want to sum (the dol­lar sign is required!). I needed lit­tle one­liner to find out how much mem­ory php was con­sum­ing on a […]

Self-extracting shell scripts

Recently at work, I had to fig­ure out on how to trans­fer some data to sys­tems used by scripts that were exe­cuted directly on the hosts. It wasn’t that much pay­load, and I really didn’t want to be both­ered to set up a sep­a­rate filesys­tem place where to hosts rsync the data from, make sure […]

Bash: Preparing and executing commands in a variable/string

When writ­ing some shell scripts, one does often have command’s argu­ments and options pre­pared in a vari­able. Aside from the usual quo­ta­tion rules, this usu­ally works fine: > cmd=“ls –a” > $cmd . .. dir1 dir2 dir3 file1 file2 Don’t do this any­more. It only works eas­ily for sim­ple com­mands. As soon as you’ve got more complex […]