PDA

View Full Version : echo into file permission denied



craigp
November 13th, 2008, 09:48 PM
from the user www-data i am trying to run this:

sudo echo -e "something" > /etc/apache2/sites-available/example.com.conf


now the reply i get when i run as su www-data i get:

"sh: /etc/apache2/sites-available/example.com.conf: permission denied"

Any help?
Cheers

taurus
November 13th, 2008, 09:50 PM
sudo echo -e "something" > sudo /etc/apache2/sites-available/example.com.conf

rjack
November 13th, 2008, 09:58 PM
Using tee
echo "ciao" | sudo tee /path/to/filehas one advantage: the program that outputs data is run as normal user, so it's safer in the general case where the program is not a simple "echo".

More on this topic in the RootSudo (https://help.ubuntu.com/community/RootSudo#Downsides of using sudo) wiki page.

sisco311
November 13th, 2008, 09:59 PM
echo -e "something" | sudo tee /etc/apache2/sites-available/example.com.conf

to append the file:

echo -e "something" | sudo tee -a /etc/apache2/sites-available/example.com.conf

craigp
November 13th, 2008, 10:21 PM
thanks guys that worked perfectly

sisco311
November 13th, 2008, 10:28 PM
Cool!

Please mark the thread solved by selecting
Mark this thread as solved from the Thread Tools.

Cracauer
November 13th, 2008, 11:05 PM
Or

sudo sh -c "echo foo > /blah"