Вопрос

I'm doing a script and I would like to add the following line

pre-up iptables-restore < /etc/iptables.rules

to the file interfaces which is located on /etc/network/interfaces,but although I have enabled the permissions to write in this file(I work in Ubuntu), I'm not able to do it... I'm trying to use the following command in my bash script

sudo echo "pre-up iptables-restore < /etc/iptables.rules" >> /etc/network/interfaces

Any suggestion of how to do it without using gedit o vi?

Thanks in advance!

Это было полезно?

Решение

You need to tell bash not to use redirection before it starts sudo:

sudo bash -c 'echo "pre-up iptables-restore < /etc/iptables.rules" >> /etc/network/interfaces'

this way the complete command will be executed with root access, not only the echo "pre-up iptables-restore < /etc/iptables.rules" part

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top