I'm working on a small script that loads some iptables lists and writes each line to a associated chain-file. This all works only if the script runs in an empty directory. As far as I understand correctly, this is due to the array in which I have the value * stored. As soon as a line with * is called, the value is replaced with all files in the current directory.
Do you guys know a simple solution to run the script in a non-empty folder?
here is an example of output when the script runs in ~
LOG tcp -- Bilder Dokumente Downloads Musik Öffentlich Schreibtisch Videos Vorlagen eth1 !125.238.212.131 0.0.0.0/0 tcp dpt:45 LOG flags 0 level 4 prefix `LOGSMTP '
LOG tcp -- Bilder Dokumente Downloads Musik Öffentlich Schreibtisch Videos Vorlagen eth1 !125.238.212.131 0.0.0.0/0 tcp dpt:225 LOG flags 0 level 4 prefix `LOGSMTP '
and here is an example of the output when it runs in an empty folder (it should look like this)
LOG tcp -- * eth1 !125.238.212.131 0.0.0.0/0 tcp dpt:45 LOG flags 0 level 4 prefix `LOGSMTP '
LOG tcp -- * eth1 !125.238.212.131 0.0.0.0/0 tcp dpt:225 LOG flags 0 level 4 prefix `LOGSMTP '
and here is the script
#!/bin/bash
cd /scripts/s.iptables.d/work
data=$(ls /scripts/s.iptables.d/iptables*)
for file in $data
do
outputpath="/output/s.iptables-"
while read -r line
do
arr=($line)
case "$line" in
Chain* ) chain=${arr[1]}
output=$outputpath$chain
inactiveoutput=$outputpath$chain"-inactive"
;;
[1-9]* ) reg="^[0-9]*\s+0\s+0.*$"
if [[ "$line" =~ "$reg" ]]
then
echo "${arr[@]:3}" >> $inactiveoutput
else
echo "${arr[@]:3}" >> $output
fi
;;
esac
done < <(cat "$file")
done
I am looking forward to any help and thank you in advance
\*, and test it*, I would have to replace every\*before it can be written. This would, substantially increase the running time. Do you have a other idea?