[clug] Made to fix it :-)
Paul Wayper
paulway at mabula.net
Tue Aug 31 06:20:22 MDT 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
Just thought I'd share a little amusement from today: we had to search through
some logs for stuff. There are quite a few log files per day and we had to
scan through a week or so. It's an eight processor machine so I wanted to do
it in parallel and, in explaining the problem to a friend, I realised that I
had all the tools I needed: 'make'. I wrote a Makefile similar to the following:
- -8<-------------
%.txt: %.gz
zgrep -e 'email at address' %< > %@ || /bin/true
SOURCES := $(wildcard *.gz)
all: $(patsubst %.gz, %.txt, $(SOURCES))
- -8<-------------
The first two lines say: things with .gz can be transformed into .txt files by
zgrep taking the source (%<) and producing the target (%@). We use '||
/bin/true' because grep has an annoying habit of returning false if the
pattern wasn't found, and make detects this and thinks this a failure to build
the source file; so we convince it that whatever it returns, it returns true.
Then we collect a list of the source files, and make the 'all' target depend
on a list of those files with the .gz extensions changed to .txt. A 'make -j
8' and away it goes :-) And the best part is that if we stop the process at
any point, make will remove the half-completed .txt files and the same command
restarts the whole thing.
I know Tridge said using parallel make is a bad thing, but in this case I
think I can probably get away with it... :-)
Anyone else have some neat tricks up their sleeve to make their sysadmin life
less painful?
Have fun,
Paul
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEYEARECAAYFAkx884YACgkQu7W0U8VsXYKaUQCaA4zV3IzmCGgBy80o5a3sg7jK
ZQEAoKz2Zhg8xB0mIKmjRDxJf5YMuIaf
=3pUQ
-----END PGP SIGNATURE-----
More information about the linux
mailing list