A couple of scripting queries
From: Simon Hobson (simonsnews_at_thehobsons.codotuk)
Date: 03/24/05
- Next message: Tony Lawrence: "Re: A couple of scripting queries"
- Previous message: Bob Meyers: "Re: Multiple Print jobs hang on last page of first job"
- Next in thread: Tony Lawrence: "Re: A couple of scripting queries"
- Reply: Tony Lawrence: "Re: A couple of scripting queries"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 24 Mar 2005 18:59:45 +0000
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
- Next message: Tony Lawrence: "Re: A couple of scripting queries"
- Previous message: Bob Meyers: "Re: Multiple Print jobs hang on last page of first job"
- Next in thread: Tony Lawrence: "Re: A couple of scripting queries"
- Reply: Tony Lawrence: "Re: A couple of scripting queries"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|