开发者

Bash Deployment Script Permission Problem

I'm writing a dep开发者_如何学编程loyment script and have run in to a strange problem...

ian@baster:~$ sudo echo "Build: "$REVISION" - Deployed: "$(date +%Y-%m-%d) > /home/www/prod/www/revision.html
-bash: /home/www/prod/www/revision.html: Permission denied

but...

root@baster:~# echo "Build: "$REVISION" - Deployed: "$(date +%Y-%m-%d) > /home/www/prod/www/revision.html
root@baster:~# more /home/www/prod/www/revision.html
Build:  - Deployed: 2011-01-28

then...

ian@baster:~$ sudo ls -l /home/www/prod/www
total 28
-rw-r--r-- 1 root     root       31 2011-01-28 21:56 revision.html

ian@baster:~$ sudo more /home/www/prod/www/revision.html
Build:  - Deployed: 2011-01-28

What's the deal?


The usual way to do that is with tee:

echo "foo" | sudo tee filename

You can suppress the output to the screen which tee does like this:

echo "foo" | sudo tee filename >/dev/null


The echo is run as root, but not the redirection. Run the redirection in a sudo subshell.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜