sysrc: name contains characters not allowed in shell

Hi,

when trying to edit /etc/sysctl.conf using sysrc I get the following:

# echo $SHELL
/bin/csh

# sysrc -f /etc/sysctl.conf net.link.ether.inet.log_arp_movements=0
sysrc: net.link.ether.inet.log_arp_movements: name contains characters not allowed in shell

# uname -v
FreeBSD 12.0-RELEASE r341666 GENERIC


Same happens under /bin/sh

Thoughts anyone?

Thanks.
 
Isn't /etc/sysctl.conf a file?

I'm not trying to set a sysctl MIB variable, rather add a line to a file (to be called during startup).

It worked on 10 or so of my other VMs, just not the one I'm having trouble with.

Thanks.
 
Never heard about this command before. On my 12.0-RELEASE r341666 it's a shell script where the validation of the user input happens on line 375:

/usr/sbin/sysrc
Bash:
...
[ "$_SYSRC_SUBR"  ] || f_include $BSDCFG_SHARE/sysrc.subr
..
for name in "$@"; do
        # NB: shell expansion syntax removed first
        name="${name%%:[+=-]*}"
        name="${name%%[%#+=-]*}"
        [ "$name" = "${name#*[!$VALID_VARNAME_CHARS]}" ] || die \
                "%s: %s: name contains characters not allowed in shell" \
                "$pgm" "$name"
done

This variable is sourced from and is defined as:

Bash:
VALID_VARNAME_CHARS="0-9ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"

That's why you see the error. You could check the previous versions and verify. Frankly I don't see a reason why you would use this command instead of a simple vi /etc/sysctl.conf.
 
_martin Thanks for the reply. I'm guessing the dot is causing the problem. I'll have to check the source of my other boxes to work out why they were working (including another box with the same version of FreeBSD).

Frankly I don't see a reason why you would use this command instead of a simple vi /etc/sysctl.conf

Programmatic automation.

I was going to use grep with sed or awk but then I remembered that FreeBSD does have a way of editing RC files that has a raft of sanity checks ( sysrc).
 
_martin Thanks for the reply. I'm guessing the dot is causing the problem. I'll have to check the source of my other boxes to work out why they were working (including another box with the same version of FreeBSD).



Programmatic automation.

I was going to use grep with sed or awk but then I remembered that FreeBSD does have a way of editing RC files that has a raft of sanity checks ( sysrc).

Did you ever resolve this?

In regards to the reason to automate vi, one vi once in a while on one host is OK. One vi on one dozen simultaneously deployed hosts invites difficult to discern typos to manifest themselves after deployment. Although copy and paste is your friend in the latter case there's no good way to do it with vi. Perhaps sed, but that opens a different can of worms.

echo sort of works, provided you feel like rebuilding the file from scratch each time:
Code:
echo domain x.local > /etc/resolv.conf
echo nameserver 192.168.100.1 >> /etc/resolv.conf
echo search x.local >> /etc/resolv.conf
 
Back
Top