Bash Script to Change UFW rules from input text file

Viewed 31

I want to write a script that applies changes to UFW rules from an input text file and the format of the input file is like the below:

178.216.250.0/24
9100 22
any
80 443

finally, I want to change the UFW rules like below:

To Action From
-- ------ ----
22 ALLOW 178.216.250.0/24
9100 ALLOW 178.216.250.0/24
80 ALLOW Anywhere
443 ALLOW Anywhere
80 (v6) ALLOW Anywhere (v6)

I write this code below:

#!/bin/bash
input="input.txt"
while IFS= read -r line
do
  sudo ufw allow from $line 
done < "$input"

Rule added

ERROR: Wrong number of arguments

Rule added

Rule added (v6)

ERROR: Wrong number of arguments


how can I define do some other command in second line but get error like this:

0 Answers
Related