#!/bin/bash # Script: mutt_mbox_split.sh # Task: Script for splitting mbox files by timeframe # Author: Benjamin 'blindcoder' Schieder # E-Mail: blindcoder@scavenger.homeip.net # Version: 0.1 # global variables SCRIPTNAME=$(basename ${0} .sh) EXIT_SUCCESS=0 EXIT_FAILURE=1 EXIT_ERROR=2 EXIT_BUG=10 # variables for option switches with default values VERBOSE="n" DEBUG="n" PREFIX="" SUFFIX="" DATEBEGIN="" DATEEND="" # functions function usage { cat >&2 <&2 usage ${EXIT_ERROR} ;; :) echo "option \"-${OPTARG}\" requires an argument." >&2 usage ${EXIT_ERROR} ;; *) echo "Impossible error. parameter: ${OPTION}" >&2 usage ${EXIT_BUG} ;; esac done # skip parsed options shift $(( OPTIND - 1 )) if (( $# < 1 )) ; then echo "I need at least one argument!" >&2 usage ${EXIT_ERROR} fi if [ -z "${PREFIX}${SUFFIX}" ]; then echo "I need a prefix or suffix or both!" >&2 usage ${EXIT_ERROR} fi if [ -z "${DATEBEGIN}" ]; then echo "Please specify -b" >&2 usage ${EXIT_ERROR} fi if [ -z "${DATEEND}" ]; then echo "Please specify -e" >&2 usage ${EXIT_ERROR} fi TMP="`mktemp`" if [ ! -f "${TMP}" ] ; then echo "Could not create temporary file!" >&2 exit ${EXIT_FAILURE} fi trap 'rm -f ${TMP}' EXIT # loop through all arguments for ARG ; do if [ "${ARG##*/}" == "${ARG}" ] ; then ARG="./${ARG}" fi if [ ! -s "${ARG}" ] ; then echo "Skipping file \"${ARG}\" because it is empty." continue fi if [[ ${VERBOSE} = y ]] ; then echo "splitting file ${ARG}" echo "New file will be called ${ARG%/*}/${PREFIX}${ARG##*/}${SUFFIX}" fi cat >${TMP} <