Append to "command" in rec script

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Append to "command" in rec script

Gerard
I am attempting to create an "rc" script to start a program I am working on.
I want, if possible, for the user to enter something in the rc.conf file to be
added to the "command" string when the program is started.

EXAMPLE:

In the rc script, this is present

command=/usr/local/bin/MyProg

Now, suppose the user wanted to activate logging. They could modify the rc
script and append an "-l" to the command string. However, I would rather they
entered options in the rc.conf file

I have been trying to use something like this in the re.conf file:

MyProg_append="-l"

is there a way to get the script to automatically append that to the
"command" or would I have to use something like this:

command=/usr/local/bin/MyProg ${MyProg_append}

What happens if the variable is empty?

Thanks!

--
Carmel
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Append to "command" in rec script

Polytropon
On Thu, 8 Nov 2018 18:13:24 +0000, Carmel NY wrote:

> I am attempting to create an "rc" script to start a program I am working on.
> I want, if possible, for the user to enter something in the rc.conf file to be
> added to the "command" string when the program is started.
>
> EXAMPLE:
>
> In the rc script, this is present
>
> command=/usr/local/bin/MyProg
>
> Now, suppose the user wanted to activate logging. They could modify the rc
> script and append an "-l" to the command string. However, I would rather they
> entered options in the rc.conf file

Maybe read "man 5 rc.conf" and put non-FreeBSD (or at
least "experimental" stuff) in /etc/rc.conf.local.
The difference between rc.conf and rc.conf.local is
not as big in FreeBSD as it is in OpenBSD. ;-)



> I have been trying to use something like this in the re.conf file:
>
> MyProg_append="-l"
>
> is there a way to get the script to automatically append that to the
> "command" or would I have to use something like this:
>
> command=/usr/local/bin/MyProg ${MyProg_append}

The common way to do this is to have a _flags variable,
for example

        myprog_flags="-l"

You can then execute

        $command $myprog_flags

in the script you're sourcing rc.conf into, and then
executing the program with flags, if present.

In case you don't have this in place yet, a convenient way
to source rc.conf is this:

#!/bin/sh

if [ -z "${source_rc_confs_defined}" ]; then
        if [ -r /etc/defaults/rc.conf ]; then
                . /etc/defaults/rc.conf
                source_rc_confs
        elif [ -r /etc/rc.conf ]; then
                . /etc/rc.conf
        elif [ -r /etc/rc.conf.local ]; then
                . /etc/rc.conf.local
        fi
fi

# ... your commands here ...

This makes sure a certain "precedence" is maintained, if
you need that feature.



> What happens if the variable is empty?

An unset variable will (with sh defaults) evaluate
to the empty string. See "man sh" for "-u nounset"
if you want to get warnings about unset variables.



--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Append to "command" in rec script

Gerard
On Thu, 8 Nov 2018 19:38:53 +0100, Polytropon stated:

>On Thu, 8 Nov 2018 18:13:24 +0000, Carmel NY wrote:
>> I am attempting to create an "rc" script to start a program I am working
>> on. I want, if possible, for the user to enter something in the rc.conf
>> file to be added to the "command" string when the program is started.
>>
>> EXAMPLE:
>>
>> In the rc script, this is present
>>
>> command=/usr/local/bin/MyProg
>>
>> Now, suppose the user wanted to activate logging. They could modify the rc
>> script and append an "-l" to the command string. However, I would rather
>> they entered options in the rc.conf file  
>
>Maybe read "man 5 rc.conf" and put non-FreeBSD (or at
>least "experimental" stuff) in /etc/rc.conf.local.
>The difference between rc.conf and rc.conf.local is
>not as big in FreeBSD as it is in OpenBSD. ;-)

Actually, man 8 rc.subr is a lot more useful. However, it doesn't give me
what I want. Also, I have been having a problem with "run_rc_command"
chocking on complex startup options placed in the rc.conf file. I am still
trying to debug that one.

--
Carmel
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Append to "command" in rec script

Mateusz Piotrowski
>>On Thu, 8 Nov 2018 18:13:24 +0000, Carmel NY wrote:  
>>> I am attempting to create an "rc" script to start a program I am working
>>> on. I want, if possible, for the user to enter something in the rc.conf
>>> file to be added to the "command" string when the program is started.
>>>
>>> EXAMPLE:
>>>
>>> In the rc script, this is present
>>>
>>> command=/usr/local/bin/MyProg
>>>
>>> Now, suppose the user wanted to activate logging. They could modify the rc
>>> script and append an "-l" to the command string. However, I would rather
>>> they entered options in the rc.conf file    

Don't you look for ${name}_flags (see rc.subr(8)).
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Append to "command" in rec script

Gerard
On Thu, 8 Nov 2018 21:32:09 +0100, Mateusz Piotrowski stated:

>>>On Thu, 8 Nov 2018 18:13:24 +0000, Carmel NY wrote:    
>>>> I am attempting to create an "rc" script to start a program I am working
>>>> on. I want, if possible, for the user to enter something in the rc.conf
>>>> file to be added to the "command" string when the program is started.
>>>>
>>>> EXAMPLE:
>>>>
>>>> In the rc script, this is present
>>>>
>>>> command=/usr/local/bin/MyProg
>>>>
>>>> Now, suppose the user wanted to activate logging. They could modify the
>>>> rc script and append an "-l" to the command string. However, I would
>>>> rather they entered options in the rc.conf file      
>
>Don't you look for ${name}_flags (see rc.subr(8)).

${name}_flags
        Arguments to call command with. This is usually set in
        rc.conf(5), and not in the rc.d(8) script. The environment variable
        `flags' can be used to override this.

That calls "command", it does not append a value to it. I receive an error
that "eval" cannot handle it.

I am going to try:

load_rc_config_var name var
       Read the rc.conf(5) variable var for name and set in the current
       shell, using load_rc_config in a sub-shell to prevent unwanted side
       effects from other variable assignments.

--
Carmel
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[hidden email]"