Using variables in kickstart file

Jason Kohles email at jasonkohles.com
Thu Jul 19 15:49:13 UTC 2007


On Jul 19, 2007, at 10:07 AM, Ed Brown wrote:

>> Use python instead.
>
> Or perl.  You can substitute any parameter name you want from /proc/ 
> cmdline, in place of the string 'ip' in the example given earlier:
>
>  ip=`cat /proc/cmdline |perl -e 'if (<> =~ /\sip=(.*?)\s/) {print  
> $1}'`
>
> ESXIP=`cat /proc/cmdline |perl -e 'if (<> =~ /\sESXIP=(.*?)\s/)  
> {print $1}'`
>

Or you can use the -n option to perl, which makes it work quite a bit  
like awk anyway (see the perlrun man page)...

ESXIP=`perl -ne '/ESXIP=(\S+)/ && print $1' /proc/cmdline`


What I usually do though, is just exploit bash to do the whole  
thing.  Stick this at the top of a %pre/%post script, and it will  
take anything of the form var=value from /proc/cmdline and turn it  
into a variable you can use directly...

	set -- `cat /proc/cmdline`
	for I in $*; do case "$I" in *=*) eval $I;; esac; done


You can try it from the command line to see how it works...

[root at dev1-mgmt-01 ~]# cat /proc/cmdline
ro root=/dev/SystemVG/RootLV
[root at dev1-mgmt-01 ~]# set -- `cat /proc/cmdline`
[root at dev1-mgmt-01 ~]# for I in $*; do case "$I" in *=*) eval "$I";;  
esac; done
[root at dev1-mgmt-01 ~]# echo $root
/dev/SystemVG/RootLV

-- 
Jason Kohles
email at jasonkohles.com
http://www.jasonkohles.com/
"A witty saying proves nothing."  -- Voltaire





More information about the Kickstart-list mailing list