Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have looked for this elsewhere but not able to find something that matches my requirements.

The template below is the one I need to use :

dn: uid=$1,ou=home,dc=chan,dc=com

objectClass: organizationalPerson

objectClass: person

objectClass: inetOrgPerson

objectClass: top

cn: $2

sn: $3

userid: $1

userPassword:

I need to script in such a way that populates the following fields $1,$2,$3,$4 with the input that I give it and then outputs to a new file thus allowing to run it using the blank template.

share|improve this question

2 Answers 2

I suspect you are looking for something quite simple like a file my_script that contains:

cat <<<XXX
dn: uid=$1,ou=home,dc=chan,dc=com

objectClass: organizationalPerson

objectClass: person

objectClass: inetOrgPerson

objectClass: top

cn: $2

sn: $3

userid: $1

userPassword:
XXX

To use the above, simply run:

sh my_script fred 100 200

which will output to stdout (and can be redirected to a file).

share|improve this answer

Does there actually need to be a template file?

#!/bin/bash

echo "dn: uid=$1,ou=home,dc=chan,dc=com" > $4
echo "objectClass: organizationalPerson" >> $4
echo "objectClass: person" >> $4
echo "objectClass: inetOrgPerson" >> $4 
echo "objectClass: top" >> $4
echo "cn: $2" >> $4
echo "sn: $3" >> $4
echo "userid: $1" >> $4
echo "userPassword:" >> $4

You would run ./SCRIPTNAME Value1 Value2 Value3 OutputFileName

otherwise

You script would be:

#!/bin/bash

var1=$1
var2=$2
var3=$3
file=$4

cat TemplateFile > $file

sed -i "s/1/$var1/g" $file
sed -i "s/2/$var2/g" $file
sed -i "s/3/$var3/g" $file

and your template file would be

dn: uid=1,ou=home,dc=chan,dc=com 
objectClass: organizationalPerson
objectClass: person
objectClass: inetOrgPerson
objectClass: top
cn: 2
sn: 3
userid: 1
userPassword: 
share|improve this answer
    
Ah I did this when yours was one string, hold on I'll fix it. – Kip K yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.