Friday 21 June 2013

Refreshing memory on some basics

While going back across some Linux basics (always worth doing periodically), I was reminded of the command xfs_freeze. This command can also work on other journalled filesystems such as ext3, ext4, btrfs etc.

Also messing around with getopts bash builtin and getopt command, sample test script using getopts below

#!/bin/bash

if [ $# -eq 0 ] # Script invoked with no command-line args
then
echo "Usage: `basename $0` [-a] [-b] [-c] [-d <arg>]"
exit 99

fi

#first : suppresses error reporting from getopts
while getopts ":abcd:" option
do
case $option in
a ) echo "option a OPTIND=${OPTIND}";;
b | c ) echo "option $Option OPTIND=${OPTIND}";;
d ) echo "option d with argument \"$OPTARG\" OPTIND=${OPTIND}";;
* ) echo "Default error with options given";; # Default.
esac
done

exit $?


Note to self there must be a better way of displaying sample code in this blog.