0

Given file socat.conf

AUTOSTART=default

SOCAT_default="TCP4-LISTEN:3724,nodelay,fork,reuseaddr,su=nobody TCP4:your.wow.server.ip.address:3724,nodelay"

The relevant part of the bash script that reads this file:

[ ! -f /etc/default/socat.conf ] || . /etc/default/socat.conf

start () {
    echo "Starting $DESC:"
        maxfds
        umask 027
        cd /tmp
        if test "x$AUTOSTART" = "xnone" -o -z "x$AUTOSTART" ; then
                echo "Autostart disabled."
                exit 0
        fi
        for NAME in $AUTOSTART ; do
                ARGS=`eval echo \\\$SOCAT_$NAME`
                echo $ARGS
                start_socat
                echo " $NAME $ARGS"
        done
        return $?
}

For the full file see here: https://blog.bentrax.de/2009/08/26/socat-start-automatisieren-und-iptables-regeln-laden/

My question is, how can I add another command to socat.conf? I tried with

AUTOSTART=default,another

SOCAT_default="TCP4-LISTEN:3724,nodelay,fork,reuseaddr,su=nobody TCP4:your.wow.server.ip.address:3724,nodelay"

SOCAT_another="..."

However this did not work. I am not very familiar with bash scripts to understand the for NAME in $AUTOSTART loop. I think the answer lays there. Any ideas?

5
  • What if you try AUTOSTART="default another"? Commented Apr 13, 2014 at 20:30
  • @JoshJolly "second not found.." Commented Apr 13, 2014 at 20:33
  • Is that an issue with multiple start_socat calls? The conf/args seem to get read correctly: ideone.com/qP8aQH Commented Apr 13, 2014 at 20:39
  • Is there a reason you're using both test and [] ? Commented Apr 13, 2014 at 20:40
  • @JoshJolly solved, AUTOSTART="..", I was missing the ". Post your code as an answer... Commented Apr 13, 2014 at 20:51

1 Answer 1

1

The for NAME in $AUTOSTART works by splitting $AUTOSTART into words using the environmental variable $IFS as delimiters (default is space, tab and newline). Each word in turn is then stored in $NAME and processed within the loop until no words remain.

The solution to your problem, then, is to separate your words using spaces (or tabs, or newlines..):

AUTOSTART="default another"

The double quotes are necessary, otherwise it will be read as two separate commands, AUTOSTART=default and another (again because of word-splitting using IFS).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.