[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Sheflug] shell script challenge
Cant see why not to use /bin/date with formatting
instead of putting names into array hardcoded.
say
echo mylist_`date +%d_%B_%H.%M`.txt
will produce output:
mylist_24_July_19.57.txt
I am using such naming based on date for our db backup files (after do
bzip2 --best to them).
Well obviously it's done from the cron-ed script - I am not do it
manually :)
Best regards,
Denis.
Chris J wrote:
[ 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 ###
___________________________________________________________________
Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html
GNU the choice of a complete generation.