I'm writing a deployment 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
:You can suppress the output to the screen which
tee
does like this:The
echo
is run as root, but not the redirection. Run the redirection in a sudo subshell.