# Errors when modifying rc.local parameters with sysrc



## shrdlu19 (Jan 1, 2021)

Hello!

I have a working script in which I, in particular, make changes to the settings of network adapters using the following commands:


```
/usr/sbin/sysrc ifconfig_igb1_alias0-="inet 10.0.1.201/32 vhid 1 advskew 0"
/usr/sbin/sysrc ifconfig_igb1_10_alias0-="inet 10.0.10.201/32 vhid 10 advskew 0"
/usr/sbin/sysrc ifconfig_igb1_alias0+="inet 10.0.1.201/32 vhid 1 advskew 200"
/usr/sbin/sysrc ifconfig_igb1_10_alias0+="inet 10.0.10.201/32 vhid 10 advskew 200"
```

This work fine, but sometime something different from what I expect appears in the rc.conf. For example, today after running my script i saw in rc.conf next:


```
ifconfig_igb1_alias0="0 inet 10.0.1.201/32 vhid 1 advskew 200"
```

Sometimes something worse appears, for example:


```
ifconfig_igb1_alias0="advskew inet 10.0.1.201/32 vhid 1 200"
```

But most of the time the script works out absolutely fine!

What could be the reason for this behavior? Of course, I can modify rc.conf with 'sed' or just replace the files, but I would like to understand what is wrong with the 'sysrc' or my script?

Below is my entire script



Spoiler: carp-master-backup.sh





```
#!/bin/sh
#
# WARNING!!!
# This script is ONLY for MASTER cluster node! Do NOT start it at BACKUP node!
#
delay=1
log="local0.debug"
name="carp"
#
/usr/bin/logger -p $log -t $name "Master/backup switcher script started with params $1 $2"
case "$2" in
        MASTER)
                /usr/bin/logger -p $log -t $name "Switch to MASTER mode"
                /bin/sleep $delay

                /bin/rm -f /var/tmp/.monit.state
                /usr/sbin/sysrc monit_enable="YES"
                /usr/sbin/service monit start
                /usr/local/bin/monit monitor all

#
#       MASTER-only section
#       Next commands is ONLY for MASTER cluster node!
#
/usr/sbin/sysrc ifconfig_igb1_alias0-="inet 10.0.1.201/32 vhid 1 advskew 200"
/usr/sbin/sysrc ifconfig_igb1_10_alias0-="inet 10.0.10.201/32 vhid 10 advskew 200"
/usr/sbin/sysrc ifconfig_igb1_alias0+="inet 10.0.1.201/32 vhid 1 advskew 0"
/usr/sbin/sysrc ifconfig_igb1_10_alias0+="inet 10.0.10.201/32 vhid 10 advskew 0"

#
#       MASTER-only section end
#

                /usr/sbin/sysrc nginx_enable="YES"
                /usr/sbin/service nginx start

                /usr/sbin/sysrc squid_enable="YES"
                /usr/sbin/service squid start

                /usr/sbin/sysrc privoxy_enable="YES"
                /usr/sbin/service privoxy start

                /usr/sbin/sysrc tor_enable="YES"
                /usr/sbin/service tor start

                /usr/sbin/sysrc openvpn_enable="YES"
                /usr/sbin/service openvpn start

                /usr/bin/crontab -u root /usr/local/etc/squid/scripts/crontab-master
                /usr/sbin/service cron restart

                /usr/bin/logger -p $log -t $name "Switch to MASTER mode OK"

        ;;
        BACKUP)
                /usr/bin/logger -p $log -t $name "Switch to BACKUP mode"

                /usr/sbin/service monit stop
                /usr/sbin/sysrc monit_enable="NO"

                /usr/bin/crontab -u root /usr/local/etc/squid/scripts/crontab-backup
                /usr/sbin/service cron restart

                /usr/local/sbin/squid_emergency_stop.sh
                /usr/sbin/sysrc squid_enable="NO"

                /usr/sbin/service privoxy stop
                /usr/sbin/sysrc privoxy_enable="NO"

                /usr/sbin/service tor stop
                /usr/sbin/sysrc tor_enable="NO"

                /usr/sbin/service openvpn stop
                /usr/sbin/sysrc openvpn_enable="NO"

                /usr/sbin/service nginx stop
                /usr/sbin/sysrc nginx_enable="NO"

                /bin/sleep $delay

#
#       MASTER-only section
#       Next commands is ONLY for MASTER cluster node!
#
/usr/sbin/sysrc ifconfig_igb1_alias0-="inet 10.0.1.201/32 vhid 1 advskew 0"
/usr/sbin/sysrc ifconfig_igb1_10_alias0-="inet 10.0.10.201/32 vhid 10 advskew 0"
/usr/sbin/sysrc ifconfig_igb1_alias0+="inet 10.0.1.201/32 vhid 1 advskew 200"
/usr/sbin/sysrc ifconfig_igb1_10_alias0+="inet 10.0.10.201/32 vhid 10 advskew 200"

#
#       MASTER-only section end
#

                /usr/bin/logger -p $log -t $name "Switch to BACKUP mode OK"
        ;;
esac

exit 0
```


----------



## im (Jan 1, 2021)

Hello!
Seems like all the sysrc's run in one time and currupt your config.

Try to put in order running those sysrc's. Use '&&'  for run sysrc 'one by one'

for example:

```
/usr/sbin/sysrc ifconfig_igb1_alias0-="inet 10.0.1.201/32 vhid 1 advskew 0" && /usr/sbin/sysrc ifconfig_igb1_10_alias0-="inet 10.0.10.201/32 vhid 10 advskew 0" && /usr/sbin/sysrc ifconfig_igb1_alias0+="inet 10.0.1.201/32 vhid 1 advskew 200" && /usr/sbin/sysrc ifconfig_igb1_10_alias0+="inet 10.0.10.201/32 vhid 10 advskew 200"

or

/usr/sbin/sysrc ifconfig_igb1_alias0-="inet 10.0.1.201/32 vhid 1 advskew 0" &&\
/usr/sbin/sysrc ifconfig_igb1_10_alias0-="inet 10.0.10.201/32 vhid 10 advskew 0" &&\
/usr/sbin/sysrc ifconfig_igb1_alias0+="inet 10.0.1.201/32 vhid 1 advskew 200" &&\
/usr/sbin/sysrc ifconfig_igb1_10_alias0+="inet 10.0.10.201/32 vhid 10 advskew 200"
```


----------



## shrdlu19 (Jan 1, 2021)

*im*
Perhaps you are right... I will try! Thank you!


----------

