Click to See Complete Forum and Search --> : pipe text to a specific line


luigi6699
07-04-2005, 04:48 PM
I'm trying to automate opening a port on my system. In order to make the port opening permanent, I would like to use the PERMIT line in my rc.firewall script. I can grep out the fact that the target line is number 45 but how can I use a shell command to add to or replace this line?

Presently, the output of

grep -n PERMIT= ~/rc.firewall |grep 45 |cut -d ":" -f2
is
PERMIT="22 21"

that is the target line. Is there a way to use echo, cat, awk or sed to rewrite that line as

PERMIT="22 21 192.168.168.168:80"

instead?

flukshun
07-04-2005, 04:57 PM
sed -i 's/^PERMIT.*/PERMIT="whatever you want to replace the variable with"/' <filename>

make a backup before you use it i havent really tested it

bwkaz
07-04-2005, 10:04 PM
Why add a line to the firewall script? Why not just run the iptables command that will open the port?

You can even use iptables-save afterward, and iptables-restore in the rc.firewall script, if you want the port to remain open over a reboot.