[Spacewalk-list] Code Snippet Question

Wojtak, Greg (Superfly) GregWojtak at quickenloans.com
Fri Apr 13 18:49:51 UTC 2012


Thanks for the clarification.  Basically all I'm trying to do is run
insert a shell case statement using the ksmeta variable as a switch.  It
sounds like I can do something like

ENV = $getVar("$env", "")
#raw
switch $ENV in
...
#endraw



On 2012-04-13 2:35 PM, "Josh Preston" <JoshPreston at dswinc.com> wrote:

>Greg,
>
>You won't be able to use ksmeta data inside of a #raw ... #end raw block
>the way you are trying to...  The #raw block tells cobbler not to process
>$variables ... use it mainly when there are tons of shell variables that
>cobbler should not process.  I'd recommend limiting the use of #raw as
>much as possible and when you do have to use it, use it to avoid a lot of
>shell variable escaping.  It might help to think of cobbler as the
>pre/post script GENERATOR, not the shell interpreter.
>
>For example:
>
>    #raw
>    echo $test
>    #end raw
>
>is equivalent to:
>
>    echo \$test
>
>Neither of which cobbler would process and would end up as:
>
>    echo $test
>
>in the kickstart script / snippet
>
>--OR --
>
>You could do something like:
>
>    env = $getVar("$env", "")
>    #raw
>    
>    ...
>    echo $env
>    ...
>    
>    #end raw
>
>This will declare the variable for the shell, so when your script it
>running, $env is set and cobbler didn't need to do the substitution.
>
>---
>
>For reference, I use this formula in my snippets so that I can use
>ksmeta, command line options or cobbler system data (notice the minimal
>use of #raw):
>
># 1. if the system's hostname is not set or equals localhost.localdomain
>or it's set to ip address
>#   a. configure the hostname using the kernel command line options
>#   b. configure the hostname using cobbler system data
># 2. create our valid /etc/hosts entries
>
>#set $HOSTNAME = $getVar("$hostname", "$hostname")
>#set $GATEWAY = $getVar("$gateway", "$gateway")
>#set $IP = $getVar("$ip", "$ip")
>
>HOSTNAME="$HOSTNAME"
>GATEWAY="$GATEWAY"
>IP="$IP"
>
>#if $getVar("$system_name", "") == ""
>    #raw
>for I in $(cat /proc/cmdline); do
>    case "$I" in *=*)
>        eval $I; export $I;
>    esac;
>done
>    #end raw
>#end if
>
>
>Josh Preston
>Shoe Lover & Unix Admin
>
>_______________________________________________
>Spacewalk-list mailing list
>Spacewalk-list at redhat.com
>https://www.redhat.com/mailman/listinfo/spacewalk-list





More information about the Spacewalk-list mailing list