
03-17-2009
|
|
Shell programmer, author
|
|
|
Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
|
|
Quote:
Originally Posted by GoldenEye4ever
I need to execute a command that is loaded from a file.
Basically, we have several scripts that need to be run at scheduled times.
We're going to store those times in the database and update a file with data.
|
Wouldn't it be easier to use a cron job?
Quote:
In that file we'll have scriptName, inputParameters, runTimes, etc...
I chose to use tilda (~) as the delimiter as it can't be used by any of the input variables 
I got it all working, with one exception.
If an inputParameter needs to be executed (current date `date +'%d%m'`)
Then I get this error:
Code:
./chk_master_script.sh[247]: `date +%m%d`: not found
Launching script (with parameters): $HOME/daily/scripts/workit.sh
This is roughly how I load the data:
Code:
if [ -s ${masterDataFile} ]; then
fileExists=true
IFS="~"
while read workerScript parameters timingStuff; do
...
params=`${parameters}`
|
According to the contents you posted, the backticks are already there. Use eval to execute it:
Code:
eval "params=${parameters}"
Quote:
Code:
echo "Launching script (with parameters): ${workerScript} ${params}"
...
done
File Layout:
Code:
filename~parameters~schedulingStuffHere
Sample File Contents:
Code:
workerScript.sh~`date '+%m%d'`~stuffGoesHere
Thanks
|
Code:
if [ -s ${masterDataFile} ]; then
fileExists=true
while IFS="~" read workerScript parameters timingStuff; do
...
eval "params=${parameters}"
echo "Launching script (with parameters):"
${workerScript} ${params}
...
done
Depending on the cntents of $params, you may need to quote the expansion:
Code:
${workerScript} "${params}"
|