From owner-freebsd-questions Sun Sep 30 14:22:27 2001 Delivered-To: freebsd-questions@freebsd.org Received: from sage-american.com (sage-american.com [216.122.141.44]) by hub.freebsd.org (Postfix) with ESMTP id 52EAA37B416 for ; Sun, 30 Sep 2001 14:18:50 -0700 (PDT) Received: from sageone (ppp-208-191-235-200.dialup.crchtx.swbell.net [208.191.235.200]) by sage-american.com (8.9.3/8.9.3) with SMTP id QAA28902; Sun, 30 Sep 2001 16:18:41 -0500 (CDT) Message-Id: <3.0.5.32.20010930161904.03f12c60@mail.sage-american.com> X-Sender: jacks@mail.sage-american.com X-Mailer: QUALCOMM Windows Eudora Pro Version 3.0.5 (32) Date: Sun, 30 Sep 2001 16:19:04 -0500 To: Mike Meyer From: jacks@sage-american.com Subject: Re: Scripting question Cc: questions@FreeBSD.ORG In-Reply-To: <15287.35274.798595.307311@guru.mired.org> References: <72642935@toto.iv> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" 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 Hello & thanks for the reply, Mike and sorry for not being very clear. The script is to run under "/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.... 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 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message