The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 03-17-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by GoldenEye4ever View Post
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}"