0

I've got an ini file with several variables in it. Which i source from my bash script.

smb.ini:

USERNAME=bridge01.test
PASSWORD="8934v98nt3jiogt"
SHARE="//test.one.test.nl/Data/"
DOMAIN=ONE
USERDNS=one.test.nl
INTERFACE=eth0
IPALLOWED="172.1.50.95"
DNSSERVERS=172.2.1.21,172.17.1.11,10.2.1.10
HOSTNAME=bridge01.test

When I add these variables in my bash everything works as usual, but I want it to be configured by the ini file.

This is the output from the script when sourcing from smb.ini:

Adding firewall rules
' not found.8.7 (nf_tables): host/network `172.1.50.95
Try `iptables -h' or 'iptables --help' for more information.
172.1.50.95
' not found.8.7 (nf_tables): host/network `172.1.50.9

This is the script:

config_file="smb.ini"
source "$config_file"

    # Loop through the IP addresses and allow traffic from them
for IPS in $IPALLOWED
do
    echo $IPS
    # Allow traffic from the current IP address on TCP ports 137, 139, and 445
    iptables -I INPUT -s "$IPS" -p tcp -m multiport --dports 137,139,445 -m state --state NEW -j ACCEPT
    echo "Allowed traffic from $IPS"
    iptables-restore < /etc/iptables
    iptables-save
done

It seems to add \n to the IP?

Please note: I need to add several IPs to unblock.

Lucas
  • 7
  • 3
  • 1
    Is this possibly a \r\n v. \n issue? Did you create the ini file on Windows and then `source` it on Linux? – EdmCoff Mar 17 '23 at 14:42
  • 1
    What's the output of the command `file smb.ini` ? – M. Nejat Aydin Mar 17 '23 at 15:37
  • I don't see `Adding firewall rules` in your script - where does it come from in your output? – tink Mar 17 '23 at 17:58
  • 1
    This looks a lot like your smb.ini file has DOS/Windows line endings, which cause a variety of problems with unix tools. See ["Are shell scripts sensitive to encoding and line endings?"](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings) for more info on how to detect & fix this. – Gordon Davisson Mar 17 '23 at 18:13
  • After reading all the command I want to thank all of you. I think it's the encoding indeed. I made the script through ssh and the ini in notepad++ on windows. I was getting nuts figuring this out, lol. – Lucas Mar 18 '23 at 18:28

0 Answers0