You are not logged in.
Pages: 1
Here is one that has been bugging me off and on for some time.
I want to execute a program using sudo, and redirect its output some place to which user invoking sudo does not not have write permission
Simplistically, something like:
JoeUser$ sudo echo "Appended stuff" >> /etc/afile
I understand why this won't work, but for the life of me, I cannot find an incantation that works. I think it is complicated by the use of commands that are intrinsic to the shall (cat, echo)
I have been through the zsh and bash manuals and have tried various commands to define a block of code to no avail.
Any hints?
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
I got this to work:
$ echo "mytext" | sudo tee /etc/myfile
This also worked:
$ sudo bash -c "echo \"more_text\" >> /etc/myfile"
Offline
Hate to tell a forum mod to RTFM, but:
sudo sh -c "cd /home ; du -s * | sort -rn > USAGE"
Offline
echo "foo" > bar -> echo "foo" | sudo tee bar
echo "foo" >> bar -> echo "foo" | sudo tee -a bar
Offline
Hate to tell a forum mod to RTFM, but:
man sudo wrote:sudo sh -c "cd /home ; du -s * | sort -rn > USAGE"
If the shoe fits....
Thanks everyone. The pipe works in a lot of cases.
Invoking bash with sudo and passing commands is the obvious way (once someone points it out). I guess I could not break out of the box I had built in order to look at the problem from a different angle.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Pages: 1