[opensuse] bash - howto sudo echo X >> Y (sed?)
Guys, I have an interesting question. I have a file that I need to append information to that is owned by root. Initially I wanted to use echo: sudo echo "X" >> y.txt But, of course the echo has root privileges, but the redirection does not. So then I though about sed. It works, but how do I tell sed to 'append to end of file'? The last word in the existing file is custompkgs, but that isn't guaranteed to stay that way. As it sits, I can: sudo sed -i '/\/custompkgs/s#$#\n\n[local]\nServer = file:///repo\n#' $CHROOT/root/etc/repo.conf How can I omit searching for a word and just tell sed to append at end of file? Or, how can I use echo or cat to do the same thing, but overcome the lack of privilege on the >> ? -- David C. Rankin, J.D.,P.E. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 03/11/2012 01:27 PM, David C. Rankin wrote:
Guys,
I have an interesting question. I have a file that I need to append information to that is owned by root. Initially I wanted to use echo:
sudo echo "X" >> y.txt
But, of course the echo has root privileges, but the redirection does not. So then I though about sed. It works, but how do I tell sed to 'append to end of file'?
The last word in the existing file is custompkgs, but that isn't guaranteed to stay that way. As it sits, I can:
sudo sed -i '/\/custompkgs/s#$#\n\n[local]\nServer = file:///repo\n#' $CHROOT/root/etc/repo.conf
How can I omit searching for a word and just tell sed to append at end of file?
Or, how can I use echo or cat to do the same thing, but overcome the lack of privilege on the >> ?
sudo bash -c "echo testing >>/root/test" The answer is in "man sudo" Regards, Jim Cunning -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Sunday 11 March 2012 15:27:25 David C. Rankin wrote:
Guys,
I have an interesting question. I have a file that I need to append information to that is owned by root. Initially I wanted to use echo:
sudo echo "X" >> y.txt
sudo bash -c "echo X >> y.txt" works. Or you can put the whole thing in a script and just do sudo script.sh
sudo sed -i '/\/custompkgs/s#$#\n\n[local]\nServer = file:///repo\n#' $CHROOT/root/etc/repo.conf
How can I omit searching for a word and just tell sed to append at end of file?
~> cat foo foo ~> sed -ie '$a \bar' foo ~> cat foo foo bar Anders -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
[11.03.2012 21:27] [David C. Rankin]:
Guys,
I have an interesting question. I have a file that I need to append information to that is owned by root. Initially I wanted to use echo:
sudo echo "X" >> y.txt
But, of course the echo has root privileges, but the redirection does not. So then I though about sed. It works, but how do I tell sed to 'append to end of file'?
The last word in the existing file is custompkgs, but that isn't guaranteed to stay that way. As it sits, I can:
sudo sed -i '/\/custompkgs/s#$#\n\n[local]\nServer = file:///repo\n#' $CHROOT/root/etc/repo.conf
How can I omit searching for a word and just tell sed to append at end of file?
Or, how can I use echo or cat to do the same thing, but overcome the lack of privilege on the >> ?
Hi David, have a look at <https://help.ubuntu.com/community/RootSudo#Downsides_of_using_sudo>, they show two ways how to work around sudo's limitations. HTH Werner -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
participants (4)
-
Anders Johansson
-
David C. Rankin
-
Jim Cunning
-
Werner Flamme