Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 Sep 2001 16:41:43 -0500
From:      jacks@sage-american.com
To:        Mike Meyer <mwm@mired.org>
Cc:        questions@FreeBSD.ORG
Subject:   Re: Scripting question
Message-ID:  <3.0.5.32.20010930164143.03f12c60@mail.sage-american.com>
In-Reply-To: <15287.37107.152005.239322@guru.mired.org>
References:  <3.0.5.32.20010930161904.03f12c60@mail.sage-american.com> <72642935@toto.iv> <3.0.5.32.20010930161904.03f12c60@mail.sage-american.com>

next in thread | previous in thread | raw e-mail | index | archive | help
I'll try that... thanks!

At 04:38 PM 9.30.2001 -0500, Mike Meyer wrote:
>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?
>
>	<mike
>
>> 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
>> >
>> >--
>> >Mike Meyer <mwm@mired.org>			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 <mwm@mired.org>			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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3.0.5.32.20010930164143.03f12c60>