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
Kickstart File Georgesaa UNIX for Advanced & Expert Users 2 06-12-2008 07:17 AM
kickstart file questions beeloo UNIX for Advanced & Expert Users 1 05-08-2008 05:55 PM
how to modify a file using shell script syamkp Shell Programming and Scripting 1 03-07-2008 08:16 AM
Modify script to generate a log file heprox Shell Programming and Scripting 2 06-14-2006 07:40 AM
Redhat AS 3.0 Kickstart file issue Acleoma Linux 2 08-27-2004 06:36 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-02-2008
Registered User
 

Join Date: Apr 2008
Posts: 20
Simple script to modify kickstart file

Hi,

I would like to create a script so that it will ask me the following:

1) What is the ip address?
2) What is the gateway address?
3) What is the hostname?

and then put the answer to the below kickstart file (kickstart.cfg)



Here I included the kickstart.cfg:

# Kickstart file automatically generated by anaconda.

install
nfs --server=10.10.10.200 --dir=/vault/redhat/rhel5/5.1/x86_64
key --skip
lang en_US.UTF-8
keyboard us
xconfig --startxonboot
network --device eth0 --bootproto static --ip 10.10.10.20 --netmask 255.255.255.0 --gateway 10.10.10.1 --nameserver
10.10.10.100--hostname abc
network --device eth1 --onboot no --bootproto dhcp --hostname abc
rootpw --iscrypted $1$r3I9vk75$JWCGlXqgYd0/55lfg09NJ.
firewall --disabled
authconfig --enableshadow --enablemd5
selinux --disabled
timezone --utc America/New_York
bootloader --location=mbr --driveorder=sda --append="rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all --drives=sda
part /boot --fstype ext3 --size=100 --ondisk=sda
part pv.6 --size=0 --grow --ondisk=sda
volgroup VolGroup00 --pesize=32768 pv.6
logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=25600
logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=8192
logvol /abc --fstype ext2 --name=LogVol03 --vgname=VolGroup00 --size=25216
logvol /var --fstype ext3 --name=LogVol02 --vgname=VolGroup00 --size=10240
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-03-2008
Registered User
 

Join Date: Jun 2007
Location: Pennsylvania
Posts: 39
So star out and create the script.

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.
Reply With Quote
  #3 (permalink)  
Old 05-08-2008
Registered User
 

Join Date: Apr 2008
Posts: 20
Sorry. I still don't know how. Could you please send me a sample script?

Thanks alot.
Reply With Quote
  #4 (permalink)  
Old 05-08-2008
Registered User
 

Join Date: Mar 2008
Posts: 15
[root@atlantis ~]# cat generateKickstartConfig.sh

Code:
#!/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.
Reply With Quote
  #5 (permalink)  
Old 05-09-2008
Registered User
 

Join Date: Apr 2008
Posts: 20
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.

install
nfs --server=10.10.10.200 --dir=/redhat/install
key --skip
lang en_US.UTF-8
keyboard us
xconfig --startxonboot
network --device eth0 --bootproto static --ip $IP --netmask 255.255.255.0 --gateway $GATEWAY --nameserver 172.27.200.215,172.27.201.215 --hostname $HOSTNAME
network --device eth1 --onboot no --bootproto dhcp --hostname $HOSTNAME
rootpw --iscrypted $1$r3I9vk75$JWCGlXqgYd0/55lfg09NJ.
firewall --disabled
authconfig --enableshadow --enablemd5
selinux --disabled
Reply With Quote
  #6 (permalink)  
Old 05-09-2008
Registered User
 

Join Date: Mar 2008
Posts: 15
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.
Reply With Quote
  #7 (permalink)  
Old 05-15-2008
Registered User
 

Join Date: Apr 2008
Posts: 20
Basically I want to copy the original kickstart file to a new file call newks.cfg and insert the "network" statement to the 9th line of the newks.cfg

Here is my script, but it doesn't work...it only add to the bottom of the line to newks.cfg. Please help.




#!/bin/sh

NEW_FILE=newks.cfg
OLD_FILE=oldks.cfg

echo -en "What is the IP Address?"
read IP

echo -en "What is the gateway Address?"
read GATEWAY

echo -en "What is the Hostname?"
read HOSTNAME

/bin/cp ${OLD_FILE} ${NEW_FILE}

echo "network --device eth0 --bootproto static --ip ${IP} --netmask 255.255.255.0 --gateway ${GATEWAY} --nameserver 172.27.200.215,10.72.201.215 --hostname ${HOSTNAME}" >> ${NEW_FILE}
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:14 AM.


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

Content Relevant URLs by vBSEO 3.2.0