| Neil Cherry 2007-08-31, 7:17 pm |
| On Fri, 31 Aug 2007 07:04:44 -0700, janet wrote:
> On Aug 31, 8:46 am, Janet <jow...@wehco.com> wrote:
[vbcol=seagreen]
> #!/bin/csh -f
> # /usr/bin/clean_mereports
> # create monthly directory and move month-end reports to an archive
> folder to save these
>
> # CREATE MONTHLY DIRECTORY
> set mon=`date +%m`
> set yr=`date +%Y`
> @ mon = $mon - 1
> @ yr = $yr
> mkdir /spool/mearchives/retl/$mon$yr
>
> # MOVE FILE TO /SPOOL/MEARCHIVES
> find /spool/nti/retl -type file -a -name "*" -print|xargs -i -t cp {} \
> /spool/mearchives/retl/$mon$yr >> & /tmp/clean_mereports.log
The problem is the if the Month is August (08) or september (09) they
don't exist in Octal. What you need to do is convert 08 into 8, then
do the math, then convert it back to 08 for the rest of the commands.
The shell won't matter as bash, sh and csh all treat the 08 as an
octal. Your work around may be something like this (done in shell,
not csh):
# Interesting problem, what is 08? According to shell it doesn't exists it
# thinks the number is octal!
case "x${mon}" in
"x08")
mon=8
;;
"x09")
mon=9
;;
*)
mon=${M}
;;
esac
Then if you have printf (it's on Linux as a command, not just a C
function) on your system you can do something like this:
str=`printf "/spool/mearchives/retl/%02d%s" $mon $yr`
mkdir $str
Otherwise you'll need something else such as awk. If you need Perl
you might as well write the whole thing in Perl.
--
Linux Home Automation Neil Cherry ncherry@linuxha.com
http://www.linuxha.com/ Main site
http://linuxha.blogspot.com/ My HA Blog
Author of: Linux Smart Homes For Dummies
|