[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sheflug] shell script challenge



On 2003.07.24 19:20, Chris J wrote:
Written for ksh; will this do the job? It seems to work with some really
really brief testing, so usual disclaimers apply :)
Hmm it doesn't want to play nicely
/home/simon/listchange.ksh[34]: [: adns-discuss [at] chiark.greenend.org.uk: unexpected operator/operand

being the error, slightly modified script attached.
I'm using the public domain ksh that comes with debian BTW which calims to be version 5.2.14

Simon
#!/usr/bin/ksh

LIST_ROOT="/home/simon/testmail1"
LISTDIR="${LIST_ROOT}/lists"
ARCHIVE="${LIST_ROOT}/archive"
LASTMONTH="${LIST_ROOT}/lastmonth"

months[0]='January';	months[1]='Febuary';	months[2]='March'
months[3]='April';	months[4]='May';	months[5]='June'
months[6]='July';	months[7]='August';	months[8]='September'
months[9]='October';	months[10]='November';	months[11]='December'

integer year
integer oldmonth
integer thismonth

year=`date +%Y`
thismonth=`date +%m`

oldmonth='(thismonth + 9) % 12'
[[ $oldmonth -gt $thismonth ]] && year=year-1

cd ${LASTMONTH}
if [ -f * ]
then
	mkdir -p ${ARCHIVE}/${year}/${months[$oldmonth]}
	mv ${LASTMONTH}/* ${ARCHIVE}/${year}/${months[$oldmonth]}
fi

cd $LISTDIR
if [ -f * ]
then
	mv * $LASTMONTH
fi