Inside the script echo your questions and then read the answer to assign it to a variable. Ex:
echo "What is the ip address?"
read ipaddress
What is the gateway address?
read gatewayaddress
What is the hostname?
read hostname
So now you have your answers assigned to variables. Now echo each line of your kickstart file, but instead of the IP address you listed below, now replace it with $ipaddress.
#!/bin/sh
#define outputfile
KS_CONFIG=ks.cfg
echo -e "Starting Kickstart Configuration Generator Script ...\n"
echo -en "\tWhat is the IP Address:"
read IP_ADDRESS
echo -en "\tWhat is the gateway Address:"
read GATEWAY_ADDRESS
echo -en "\tWhat is the DNS Server:"
read DNS_SERVER
echo -en "\tWhat is the Hostname:"
read HOSTNAME
echo "network --device eth0 --bootproto static --ip ${IP_ADDRESS} --netmask 255.255.255.0 --gateway ${GATEWAY_ADDRESS} --nameserver ${DNS_SERVER} --hostname ${HOSTNAME}" >> ${KS_CONFIG}
Remember to make the script executable
Execute with ./generateKickstartConfig.sh
Answer the 4 questions and "ls" your directory, you'll see a ks.cfg file
This is a very basic solution, there's so many possiblities, you can verify the user input to check to see if the values are valid, like if they enter an IP for hostname or vice versa, check DNS to see if these IPs resolve before using them in the kickstart, use regular expression to verify the user input, if its invalid you can loop to verify they enter something useful, I mean you can write a pretty complicated script to generate your ks.cfg file.
Thanks. I have one more question. The script above will insert another new line for the "network....". Can I make it just only add the answer to those variable in the kickstart file? Please advise. Thanks alot
# Kickstart file automatically generated by anaconda.
Sure, you can make it do anything. If you're looking at building a full ks.cfg from the ground up, you can add more questions and output to a new ks.cfg. If you have an existing template you want to use and only want to chug in a few values look at using "sed" If you only want a response for this section, you can just use a "here document" and just echo the entire ks.cfg out including the user input information for network section. Like I said, you can do pretty much anything, you probably want to look at simple bash examples while you create this script.
Start to create something and post what you have and will continue to help you out.
You're just appending by using the redirect output (>>), you need to look at sed, and search for the area where you want the chunk of text. Man sed or look at examples online to do so.
I've taken what you guys supplied and another post I found elsewhere and combined it with some sed to make it work the way i want it to. Put this at the end of your ks.cfg file in a %pre section and it will ask you for the network information:
%pre
#!/bin/sh
chvt 3
echo "--Static Network Configuration--"
echo -en "What is the IP Address? : "
read ip
echo -en "What is the Netmask? : "
read netmask
echo -en "What is the Hostname? : "
read host
echo -en "What is the Gateway? : "
read gateway
echo -en "What is the Name Server?"
read nameserver