user@xxx:~$ sudo -u root xxxxx.sh >> /var/log/sample.log如果user用户对日志文件/var/log/sample.log没有写入权限(前提是user具有了sudo权限),
那么此命令不会运行成功。这是因为重定向命令没有sudo的权限。
我们可以用一种迂回的方法解决此问题,就是用tee代替>>, 如下:
user@xxx:~$ sudo -u root xxxxx.sh | sudo -u root tee -a /var/log/sample.log