Help executing command loaded from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help executing command loaded from file
# 1  
Old 03-17-2009
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 Smilie

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 Smilie
# 2  
Old 03-17-2009
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 Smilie

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 Smilie

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  
Old 03-17-2009
Thanks a lot cfajohnson,
you rule Smilie

But now I have another question Smilie

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

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 Smilie
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 01:50 AM..
# 4  
Old 03-17-2009

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

  for parm
  do
    eval "printf '%s ' $parm"
  done
}

# 5  
Old 03-17-2009
Thank you so much Smilie

You are the best
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Write pid and command name to a txt file while executing a bash script

Hi All, Just have a requirement, I am executing a bash shell script, my requirement is to catch the pid and job name to a txt file in the same directory, is there anyway to do it? please help me out. Regards Rahul ---------- Post updated at 08:42 AM ---------- Previous update was at... (2 Replies)
Discussion started by: rahulkalra9
2 Replies

2. UNIX for Dummies Questions & Answers

Find command not executing for copying file

Buddies, I am trying to copy the file 'xcopyq' from /home/sandip to /home/sandip/testdir using the below command and getting the error as shown below:- sandip@manu:~$ find /home/sandip -type f -name '*xcopyq*' -exec cp{} /home/sandip/testdir/ \: find: missing argument to `-exec' Am I... (2 Replies)
Discussion started by: sandip250382
2 Replies

3. Solaris

file just loaded does not appear to be executable

Hi When i m trying the boot the system with Primary HDD (c1t0d0s0) -- its solaris 10 I m getting an error "file just loaded does not appear to be executable".....So will anyone share the steps to recover from this stage I also tried to build the corrupted superblock from below command but... (0 Replies)
Discussion started by: taruntan
0 Replies

4. Shell Programming and Scripting

How to get total records loaded from sqlldr log file

Hi, I am loading data in the database table through sqlldr. I have to find total records loaded from sqlldr log file and store it in a variable in my script. How do I get it? Thank you. (3 Replies)
Discussion started by: mrpranab
3 Replies

5. Shell Programming and Scripting

Check if file is loaded completely and then process the file

I need to write a script which checks for files loaded into a folder (files are loaded by ftp from other server) and process the file only if the file is loaded completely. if the file is not complete in the current run, it must be processed in the next run. Any suggestions would be welcome... (2 Replies)
Discussion started by: kalyan381
2 Replies

6. UNIX for Dummies Questions & Answers

Problem executing find file command in Linux

When trying to find a list of files with specific text in them using find . -type f -exec grep -l "DataStage Job 4263" {}\; I get error find: missing argument to 'exec' How can I correct this ? I'm on Linux Red Hat. Cheers PS I'm a DataStage programmer not a systems support... (4 Replies)
Discussion started by: jackdaw_at_work
4 Replies

7. Shell Programming and Scripting

waiting until file loaded

Hello i have DB file load with this command ../SS-Tools/SSdbload -r 10 -il /export/specbackup_db/$b y i should wait until the DB load completed then run the next command $SPECROOT/bin/launchinstdbapp `/usr/bin/hostname` SS n VNM.OUT how this can be done with shell scripting NB: i... (1 Reply)
Discussion started by: mogabr
1 Replies

8. Shell Programming and Scripting

Help shell script to loop through files update ctl file to be sql loaded

I am currently trying to find a way to loop through files in a given directory and for each file modify a ctl file and sql load it. I have been using the sed command to change the infile, badfile parameters of the control file. I have not yet tried to sql load it. Requirement: files are ftp to... (1 Reply)
Discussion started by: dba_nh
1 Replies

9. Shell Programming and Scripting

How can I make the for command check to see if a file is empty before executing?

Here is the command in question for f in $(<uploads); do . I only want this to execute if uploads is not empty. If uploads is empty I want the script to quit, actually before the for command. If its not apparent uploads is a text file. Chris (3 Replies)
Discussion started by: chrchcol
3 Replies

10. Shell Programming and Scripting

executing *.bat file on windows from Unix box via ftp command

I have created get_list.bat file containing following line: dir /B /O-d >file_list.txt I am executing ftp command from Unix box and transferring get_list.bat file to windows server. In my next ftp command I am trying to execute this test.bat file by entering this line: get_list or by... (9 Replies)
Discussion started by: alx
9 Replies
Login or Register to Ask a Question