Hi,
I have a generic shell script (runBatchJob.sh) to read files (batchJob) with commands in them and execute the commands by reading the batchJob file as below
Now my problem is I'm perfectly able to execute each of the above commands from runBatchJob.sh, $BATCHJOB being replaced by /home/batchDir and so on and so forth.
But when I read the commands out of an argument file in my shell script $BATCHJOB doesn't get replaced at all and I cant run the command. When I echo the statement it prints fine.
Actual code of runBatchJob.sh
$1 being above batchJob file
I believe in above while loop, you are trying to read each line one by one from batchJob and execute that line. If so, in place of above while loop, you may try:
while read line; do
echo "Running $line"
eval $line
done < $1
Thanks Anurag but there are additional lines in the file so need to skip them, I actually included only the lines which were needed.
Raja I needed to fetch commands to be executed in a shell script from and input argument file but as the commands being fetched had env variables, they were not being evaluated hence the eval came to the rescue
You didn't mention anything about which line to execute and which line to skip. Above while loop will execute all lines in batchJob file.
Pls give some sample of batchJob and some pattern/rule to decide when to execute a line and when not.
Ok here is a simple one
first line is name of the batch Job
2nd is the name of the individual job, 3rd is the command for 1st job, 4th is again the name of 2nd individual job, 5th is the 2nd job and ...
I understand that you need to execute lines having unix script name i.e. *.sh. Will it hold true across the file?If yes, then good. Following will execute only those lines where 1st column ends with ".sh"
awk '$1 ~ /.*.sh$/' $1 | while read line; do
echo "Running $line"
eval $line
done
Yes, You may put batch file in form of XML. Put a proper tag name for command to run and script can read value inside that tag and execute that.