Search code examples
busyboxopenwrtash

BusyBox - syntax error: unexpected redirection


I'm on OpenWRT (which uses BusyBox).

When I run this script:

 while read oldIP ; do
    iptables -t nat -D PREROUTING --dst $oldIP -p tcp --dport 443 -j DNAT --to 192.168.2.1:443
 done < <(comm -23 <(sort /tmp/currentIPs) <(sort /tmp/newIPs))

I get this error:

 syntax error: unexpected redirection 

I believe that it doesn't like the "<(" part. So, my question is...How can I change this script so that BusyBox will like it?


Solution

  • The "<()" is called process substitution, and is a bash-specific feature. You need to use temporary files and a pipeline for it work on other POSIX shells.

    sort /tmp/currentIPs > /tmp/currentIPs.sorted
    sort /tmp/newIPs > /tmp/newIPs.sorted
    comm -23 /tmp/currentIPs.sorted /tmp/newIPs.sorted | while read oldIP ; do
        iptables -t nat -D PREROUTING --dst $oldIP -p tcp --dport 443 -j DNAT --to 192.168.2.1:443
    done
    rm /tmp/currentIPs.sorted /tmp/newIPs.sorted