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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to write script in tar naveeng.81 Shell Programming and Scripting 1 04-18-2008 09:04 AM
Please write this script for me nadman123 Shell Programming and Scripting 1 04-08-2008 07:30 PM
Help me to write the script gyana_cboy Shell Programming and Scripting 5 10-04-2007 11:19 PM
How to write script for this ? me_haroon AIX 0 07-01-2006 03:30 AM
Help! Need to write my first script fundidor Shell Programming and Scripting 5 01-08-2004 07:20 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-07-2006
Registered User
 

Join Date: Mar 2006
Posts: 28
script to write script

i have scripts files to create mq objects. When I have to do that in another machine, I have to copy all of them and change a few parameters from some of the files. I think, if I create a script file which takes me these parameters as input ( not sure whether we can give a file as an input of type when run only) and have all the scripts creates different scrpts file, that would be very helpful. what i mean is

say i have a script file called FF.

aaaa xxx
bbb yyy

what i want to do is
echo "aaaa xxx" >FF
echo "bbb yyy">>FF

Also want to replace if the xxx is variable. some of the parameters are fixed some of them are variable.

there are about 10 scripts file. So, I like to read one by one and create file which i can copy and use in new machine.

Can some one help me how i can do that

thanks
Reply With Quote
Forum Sponsor
  #2  
Old 03-08-2006
Klashxx's Avatar
HP-UX/Linux/Oracle
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 383
You can do the job whith macros:

$ cat FF
aaaa xxx
bbb yyy

echo "define(xxx,TEST)">out.macros


$ cat out.macros FF|m4 -B64556

aaaa TEST
bbb yyy


Bye.
Reply With Quote
  #3  
Old 03-08-2006
Registered User
 

Join Date: Mar 2006
Posts: 28
my need is to do what with many scripits files. NOt only one. The script need to pick up a file, write that, go and pick up another etc.

Also, can I give a file as an input?

thanks
Reply With Quote
  #4  
Old 03-08-2006
Klashxx's Avatar
HP-UX/Linux/Oracle
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 383
There“re multiples ways to solve the problem, basically if u do the job for one file u can do it again for other:

exem.sh:
input=$1
output=$2
{
i=1
while read line
do
FILE=$(echo $line|awk -F\; '{print $1}')
macro=$(echo $line|awk -F\; '{print $2}')
echo "${macro}$(cat ${FILE})"|m4 -B64556
(( i +=1 ))
done >${output}
} < ${input}
exit 0

where

file.one:
aaaa xxx
bbb yyy

file.two:
aaaa xxx
bbb yyy

file.conf(INPUT):
file.one;define(xxx,TEST)
file.two;define(yyy,TEST)

out(OUTPUT):
aaaa TEST
bbb yyy
aaaa xxx
bbb TEST


Cheers
Reply With Quote
  #5  
Old 03-09-2006
Registered User
 

Join Date: Mar 2006
Posts: 28
Thank you but I still did not understand how it takes up all files in the scripts directory. I will run this script in a directory where there are scripts files and I want to generate one single scripts files which generates back the scripts file into another directory but with certain parameter and file name different.

say the original directory has 6 scripts file named as

create_aaaaa
start_aaaaa
sopt_aaaaa

start_rc_aaaaa
stop_rc_aaaaa

also there are certain commands in the above files and other files whose name can be the same use aaaaa as a parameters. So, my need is create a sngle file as

echo " start_$1" >create_$1
echo " dis chl(q1.q2)" | runmqsc QM1 >>create_$1

The script file I am plannign to create has to create this single script file i explained above. It read files, add echo " takes line" > filename, if there is the parameter to change, it changes if not direct to the orignal file name

as >stoplsr
I mean this file name remains same in new directory too.

The single script file contans all the commands of all scripts files in the original script directory but paratemter changed. When I run this single script file inot new directory. similar set of files are created in the new directory but with part of file name different and some parameter name dirrerent inside some file name.

This script file has to take min 5 parameters to 10. Can these be put into a file and read as an input.

I maen, lets say out scrit to generate a single script file from a group of scripts file is generator. It has to take a file an an input where there are parameter

generator <inputfile

this generator, picks up all the scripts file one by one and generates a script file as

echo " command line, " > file name( may be start_$1)

the first part start_ is taken from the read file.

thanks
Reply With Quote
  #6  
Old 03-13-2006
Registered User
 

Join Date: Mar 2006
Location: South Yorkshire, UK
Posts: 114
Red face

Perhaps I don't understand the problem, but this looks like a strange approach.
It looks to me as if you want to generate sets of customised scripts using parameter files to define any variable items. Wouldn't it be easier to create a set of standard scripts with all the variable items parameterised and pick up the values from a file or the command line?

cheers
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0