[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Sheflug] shell script challenge
[ snip everything ... :-) ]
Written for ksh; will this do the job? It seems to work with some really
really brief testing, so usual disclaimers apply :) The lines that do the
date manipulation may need some reworking if you're ksh doesn't support it
(I have ksh93 on the Slack 8 box). If they causes problems, replace them
with:
oldmonth=$(( ($thismonth + 9) % 12))
year=$(($year - 1))
Which one goes where is left as an exercise for the reader. Beyond that,
just make sure the paths in the top few lines look right.
Chris...
#!/bin/ksh
LIST_ROOT="/home/chris/Q"
LISTDIR="${LIST_ROOT}/lists"
ARCHIVE="${LIST_ROOT}/archive"
LASTMONTH="${ARCHIVE}/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
### End of script ###
--
\ Chris Johnson \ NP: Aerosmith - 10. Permanent Vacation
\ cej [at] nightwolf.org.uk ~-----,
\ http://cej.nightwolf.org.uk/ ~-----------------------------------,
\ Redclaw chat - http://redclaw.org.uk - telnet redclaw.org.uk 2000 \____
___________________________________________________________________
Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html
GNU the choice of a complete generation.