Re: A couple of scripting queries

From: Tony Lawrence (foo_at_pcunix.com)
Date: 03/24/05


Date: Thu, 24 Mar 2005 14:15:19 -0500

Tony Lawrence wrote:
> Simon Hobson wrote:
>
>> I've been writing a script at work, mostly using Informix to extract
>> some data from the sales system - and I've come up with a couple of
>> problems that are new to me. Yes I'm sure they are bot a doddle in
>> Perl - but I haven't learned Perl (yet). This all runs in sh, not ksh,
>> and will be executed (indirectly) from cron.
>>
>>
>>
>> 1) 'double substitution' of variables
>>
>> I need to repeat the same operation for the next 11 months, so I
>> calculated the start and end dates and stored them in variables S1 to
>> S11 and E1 to E11 - thinking that I could then do something along the
>> lines of :
>>
>> for month in 1 2 3 4 5 6 7 8 9 10 11
>> do
>> echo "select <something> from <something>
>> where date_required between \"${Sn}\" and \"${En}\" " \
>> | dbaccess data -
>> done
>>
>> But then I realised that ${S${month}} doesn't work !
>>
>> In the end I did this :
>>
>> for month in 1 2 3 4 5 6 7 8 9 10 11
>> do
>> start=`echo 'echo "${S'${month}'}"' | /bin/sh`
>> end=`echo 'echo "${E'${month}'}"' | /bin/sh`
>> echo "select <something> from <something>
>> where date_required between \"${start}\" and \"${end}\" " \
>> | dbaccess data -
>> done
>>
>> I'm sure there must be a better way than start=`echo 'echo
>> "${S'${month}'}"' | /bin/sh` to do this - any ideas ?
>>
>>
>>
>> 2) date calculations
>>
>> I suspect some of you might have seen this part coming ...
>>
>> In the general case I need to process a whole pile of stuff for
>> yesterdays date (because the script will be run early in the morning).
>> So I need to get yesterdays date, and then the start and end dates for
>> that month and the following 11 months.
>>
>> At the moment I've done this with a combination of some rather
>> unpretty script and informix scripts (which I'm too embarassed to
>> quite here). Again I'm sure there'll be a better way of doing it - any
>> ideas ?
>>
>>
>>
>> TIA, Simon
>>
>
> You can get yesterday's date as simply as
>
> date --date='1 day ago'

But maybe not on SCO..

>
>
> If you want more complicated things, it's harder to do in the shell (and
> usually no reason to); see http://aplawrence.com/Unix/yesterday.html and
> for an example of doing it in perl see
> http://aplawrence.com/Unix/perlnetftp.html
>
>

And I forgot - see http://aplawrence.com/Bofcusm/1455.html and
http://aplawrence.com/SCOFAQ/FAQ_scotec6datemath.html

-- 
Tony Lawrence
Unix/Linux/Mac OS X  resources: http://aplawrence.com


Relevant Pages

  • Re: A couple of scripting queries
    ... Simon Hobson wrote: ... Yes I'm sure they are bot a doddle in Perl - but I haven't ... > date (because the script will be run early in the morning). ... > script and informix scripts. ...
    (comp.unix.sco.misc)
  • RE: ontape -l roll-forward of many logs
    ... was located too far away and the pipe was too small to use Informix HDR ... We used an EXPECT script on the hotsite..... ... until a logical log bundled was ftp'd into place by the PRD script (this ... create a bundle and then fire a script that would ftp it to the hotsite. ...
    (comp.databases.informix)
  • Re: How to pass in arguments from unix script to INFORMIX 4GL program
    ... input array arr1 without defaults from sa_arr1 ... I wish to automate this INFORMIX 4GL program by passing in the input values ... My unix script will be something as below: ...
    (comp.databases.informix)
  • RE: Informix CRONTAB problem
    ... setting of your environment variables to the top of the script. ... Subject: Informix CRONTAB problem ... output to sids without headings ... However, when run via a crontab command, the job fails with some or all ...
    (comp.databases.informix)
  • Re: How to pass in arguments from unix script to INFORMIX 4GL program
    ... I wish to automate this INFORMIX 4GL program by passing in the input values ... enter screen array with 2 fields - account No, ... My unix script will be something as below: ...
    (comp.databases.informix)