From owner-freebsd-questions Sun Sep 30 14:39: 6 2001 Delivered-To: freebsd-questions@freebsd.org Received: from guru.mired.org (okc-94-248-46.mmcable.com [24.94.248.46]) by hub.freebsd.org (Postfix) with SMTP id 50D3F37B40B for ; Sun, 30 Sep 2001 14:39:00 -0700 (PDT) Received: (qmail 31543 invoked by uid 100); 30 Sep 2001 21:38:59 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15287.37107.152005.239322@guru.mired.org> Date: Sun, 30 Sep 2001 16:38:59 -0500 To: jacks@sage-american.com Cc: questions@FreeBSD.ORG Subject: Re: Scripting question In-Reply-To: <3.0.5.32.20010930161904.03f12c60@mail.sage-american.com> References: <72642935@toto.iv> <3.0.5.32.20010930161904.03f12c60@mail.sage-american.com> X-Mailer: VM 6.90 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG jacks@sage-american.com types: > Hello & thanks for the reply, Mike and sorry for not being very clear. The > script is to run under "/bin/sh". The suggestions I made all work with /bin/sh. > The file name appears several times in a script file in the following > suffix date form as part of a string and also as a separate string: > > BEFORE CHANGE > "/usr/local/bin/myfile.01.09" > and again as just "myfile.01.09" > > I want to roll the suffix over to a new year & month on the first day of > each month, so the file would be changed to read: > AFTER CHANGE > "usr/local/bin/myfile.01.10" > and again as just "myfile.01.10" > > So, the script will need to search/replace to change the suffix in the > above two forms using the date variable as a suffix using `date +%y.%m` on > the first day of each month via a cron job. > > Hope that is a little more clear.... Um - why not just put the filename in a variable like so: FILENAME=`date +myfile.%y.%m` then use the variable instead of the filename in the script? At 04:08 PM 9.30.2001 -0500, Mike Meyer wrote: > >jacks@sage-american.com types: > >> I'm putting the finishing touches on a automated cron script & some of its > >> scripting makes calls on other scripts that contain file names that need to > >> be changed each month, but cannot necessarily use the "date" command to > >> create the variable needed. > > > >Want to describe how they need to be changed? You can do quite a bit > >with the date command and a little script magic. > > > >> What I need sounds pretty simple. I need to change a sub-script's string > >> without having to manually open the script file. e.g. change content string > >> "myfile.old" to "myfile.new"... for example: > >> #subscript > >> cp /usr/local/bin/myfile.old /somewhere/else > >> to read > >> cp /usr/local/bin/myfile.new /somewhere/else > >> > >> Thus, when the cron script calls this sub-script file (containing > >> "myfile.xxx)", it will have the new file reference name "myfile.new" when > >> it is supposed to be there. > > > >Well, passing the file name in as an argument is one easy way to do > >it. If you can't change the argument handling of the subscript for > >some reason, you can use an environment variable, like so: > > > >#script > >TARGETFILE=myfile.new subscript > > > >#subscript > >${TARGETFILE:=myfile.old} > >cp /usr/local/bin/$TARGETFILE /somewhere/else > > > >In the extreme case, you cram one or more commands into a variable and > >eval the variable: > > > >#script > >VARIABLECOMMAND='cp /usr/local/bin/myfile.new /seomwhere/else' subscript > > > >#subscript > >eval ${VARIABLECOMMAND:-'cp /usr/local/bin/myfile.old /somewhere/else'} > > > > > > > > >-- > >Mike Meyer http://www.mired.org/home/mwm/ > >Q: How do you make the gods laugh? A: Tell them your plans. > > > >To Unsubscribe: send mail to majordomo@FreeBSD.org > >with "unsubscribe freebsd-questions" in the body of the message > > > > > > Best regards, > Jack L. Stone, > Server Admin > > Sage-American > http://www.sage-american.com > jacks@sage-american.com > -- Mike Meyer http://www.mired.org/home/mwm/ Q: How do you make the gods laugh? A: Tell them your plans. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message