27/08/2009

Put awk to work

At Atlas we love documentation, as all of you must too! Every system and service is documented into a wiki.

The first time you are told to document a system, you log into that system and start typing commands to get what you need and copy it to a wiki, then apply the appropiate format.

The second time you apply some pipe magic with the awk magic dust, and voila! the info you need as formatted as possible ;)

Some useful commands you will appreciate:

  • Getting partition table formatted, with size (change ext3 to get other fs types):
    df -P -h -t ext3 | grep -v Filesystem | awk '{print "| "$1" | "$6" | "$2" |"}'
  • Getting NFS partition mappings formatted:

    cat /etc/fstab | grep nfs | grep -v '#' | awk '{print "| "$1" | "$2" |"}'
  • Getting apache virtual host configuration:

    cat your-vhost.conf | egrep "ServerName|ServerAlias|RewriteRule|DocumentRoot|ErrorLog|CustomLog|ErrorDocument|VirtualHost|SSL" | awk '{print "| | "$1" | "$2$3$4$5$6" |"}'
    This one needs to be polished a little to get rid of those virtual hosts lines and put its info on the first column.

Put this post to your favourites as it will be updated as more info is needed to format.

Nice blog.

An optimization from my side:

$ cat /etc/fstab | grep nfs | grep -v ‘#’ | awk ‘{print “| “$1″ | “$2″ |”}’

to

$ awk ‘/nfs/ && !/^#/ {print $1,$2}’ OFS=\| /etc/fstab

few posts on awk :

http://unstableme.blogspot.com/search/label/Awk

Thanks.

Comment by Jadu Saikia — 10/09/2009 @ 19:16

Thanks Jadu!

As you can see I’m rookie in awk so any improvement to this tips are really welcome!

Comment by Kus — 11/09/2009 @ 10:14

Leave a comment

Spam protection by WP Captcha-Free