Bash script to fill in a template
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).
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: