DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 27th January 2010
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,148
Thanked 182 Times in 149 Posts
Default Formatting OpenBSD /etc/fstab file with awk

An example of an OpenBSD /etc/fstab file:
Code:
/dev/wd0a / ffs rw 1 1
/dev/wd0m /backup ffs rw,nodev,nosuid 1 2
/dev/wd0e /home/j65nko ffs rw,nodev,nosuid 1 2
/dev/wd0d /tmp ffs rw,nodev,nosuid 1 2
/dev/wd0k /usr ffs rw,nodev 1 2
/dev/wd0l /usr/local ffs rw,nodev 1 2
/dev/wd0f /var ffs rw,nodev,nosuid 1 2
/dev/wd0h /var/log ffs rw,nodev,nosuid 1 2
/dev/wd0g /var/tmp ffs rw,nodev,nosuid 1 2
A nicely formatted version:
Code:
# special       mount                                   fs      mount                                   dump    fsck
# device        point                                   type    options                                 freq    pass#
# =======       =====                                   ====    =======                                 ====    =====
#
/dev/wd0a       /                                       ffs     rw                                      1       1
/dev/wd0m       /backup                                 ffs     rw,nodev,nosuid                         1       2
/dev/wd0e       /home/j65nko                            ffs     rw,nodev,nosuid                         1       2
/dev/wd0d       /tmp                                    ffs     rw,nodev,nosuid                         1       2
/dev/wd0k       /usr                                    ffs     rw,nodev                                1       2
/dev/wd0l       /usr/local                              ffs     rw,nodev                                1       2
/dev/wd0f       /var                                    ffs     rw,nodev,nosuid                         1       2
/dev/wd0h       /var/log                                ffs     rw,nodev,nosuid                         1       2
/dev/wd0g       /var/tmp                                ffs     rw,nodev,nosuid                         1       2
The awk script to accomplish this:
Code:
# Reformat OpenBSD /etc/fstab file 
# $Id: format_fstab,v 1.1 2010/01/27 02:14:02 j65nko Exp $
# usage:  awk -f format_fstab /etc/fstab

# WARNING: first backup your original fstab file before redirecting
#          the output of this awk script to the /etc/fstab
#  cd /etc
#  cp -p fstab fstab.orig 
#  awk -f format_fstab fstab.orig >fstab
#  cat fstab
 

BEGIN {
    printf("%s\t%s\t\t\t\t\t%s\t%s\t\t\t\t\t%s\t%s\n", "# special","mount","fs","mount","dump","fsck")
    printf("%s\t%s\t\t\t\t\t%s\t%s\t\t\t\t\t%s\t%s\n","# device","point","type","options","freq","pass#")
    printf("%s\t%s\t\t\t\t\t%s\t%s\t\t\t\t\t%s\t%s\n","# =======","=====","====","=======","====","=====")
    printf("#\n")
}

{
    T2=" "
    if (length($2) >= 1 )  T2="\t\t\t\t" 
    if (length($2) >= 8 )  T2="\t\t\t" 
    if (length($2) >= 16 ) T2="\t\t"
    if (length($2) >= 24 ) T2="\t"

    T4=" "
    if (length($4) >= 1 )  T4="\t\t\t\t" 
    if (length($4) >= 8 )  T4="\t\t\t" 
    if (length($4) >= 16 ) T4="\t\t"
    if (length($4) >= 24 ) T4="\t"

    printf( "%s\t%s%s\t%s\t%s%s\t%s\t%s\n" ,$1,$2,T2,$3,$4,T4,$5,$6) 
}
# end of script
The previous version :
Code:
# --------------------------------------------------

FILE=/etc/fstab
FILE=./fstab

ORIG=${FILE}.orig

cp ${FILE} ${ORIG}      # create backup

echo Formatting ${FILE}

cat <<END >${FILE}
# special       mount           fs      mount                           dump    fsck
# device        point           type    options                         freq    pass# 
# ======        =====           ====    =======                         ====    =====
#
$(awk '{ printf("%s\t%s\t\t%s\t%s\t\t\t\t%s\t%s\n", $1, $2, $3, $4, $5, $6)}' $ORIG )
/dev/cd0a       /cdrom          d9660   ro,noauto                       0       0
/dev/fd0a       /floppy         msdos   ro,noauto                       0       0
END

cat $FILE
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
 

Tags
/etc/fstab, awk

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automating OpenBSD snapshot downloads with a .netrc file J65nko Guides 1 7th January 2010 03:09 AM
table formatting (could not find better title) gosha Programming 10 19th March 2009 06:33 PM
Formatting Hard Disk Drive to UFS in OS X 10.5 Turquoise88 Other BSD and UNIX/UNIX-like 1 7th March 2009 09:57 PM
Formatting fat32 drive quickly map7 FreeBSD General 10 26th July 2008 05:17 PM
fstab and CD/DVD device corneliu FreeBSD General 7 24th May 2008 02:11 AM


All times are GMT. The time now is 04:42 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick