The UNIX and Linux Forums  

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
waiting until file loaded mogabr Shell Programming and Scripting 1 08-08-2008 11:24 AM
Help shell script to loop through files update ctl file to be sql loaded dba_nh Shell Programming and Scripting 1 04-15-2008 09:00 PM
How can I make the for command check to see if a file is empty before executing? chrchcol Shell Programming and Scripting 3 07-29-2006 04:14 AM
executing *.bat file on windows from Unix box via ftp command alx Shell Programming and Scripting 9 01-29-2006 06:31 PM
executing dir or ls command via FTP alx Shell Programming and Scripting 5 01-27-2006 06:13 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-17-2009
GoldenEye4ever GoldenEye4ever is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 5
Help executing command loaded from file

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.
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}`
    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
  #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}"

  #3 (permalink)  
Old 03-17-2009
GoldenEye4ever GoldenEye4ever is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 5
Thanks a lot cfajohnson,
you rule

But now I have another question

I've got my attributes evaluated, however I need to consider if multiple attributes are passed through, as a single string

Basically, I need to tokenize the parameters string

This is what I have so far:
Code:
...
evalParams()
{
  output=""
  input="$1"
  set -A attr $(echo ${input} | tr ',' ' ' )
  
  n="0"
  while [ "${n}" -lt "${#attr[*]}" ];
  do
    eval "p=${attr[${n}]}"
    output="${output} ${p}"
    n=`expr $n + 1`
  done
  
  echo ${output}
}
...
## this is actually loaded from file, but for the purpose of an example it's fine :)
parameters="`date +%m%d`,`date +%H%M`"
...
params=`evalParams ${parameters}`
Unfortunately, it isn't working
The attr array isn't being populated as I expected,
the entrie parameter string just gets assigned to the 1st index (index 0)



As for cronjobs, we're trying to get our scheduling in the DB.
- We want our schedules to be centralized
- Makes learning the timings of the batch easier

Last edited by GoldenEye4ever; 03-18-2009 at 12:50 AM..
  #4 (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

Code:
evalParams()
{
  oldIFS=$IFS
  IFS=,
  set -f
  set -- $1
  set +f
  IFS=$oldIFS

  for parm
  do
    eval "printf '%s ' $parm"
  done
}
  #5 (permalink)  
Old 03-17-2009
GoldenEye4ever GoldenEye4ever is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 5
Thank you so much

You are the best
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0