AWS EMR bootstrap action as sudo

做~自己de王妃 提交于 2019-12-08 19:25:35

I've not had problems using sudo from within a shell script run as an EMR bootstrap action, so it should work. You can test that it works with a simple script that simply does "sudo ls /root".

Your script is trying to append to /etc/hosts by redirecting stdout with:

sudo echo -e 'ip1 uri1' >> /etc/hosts

The problem here is that while the echo is run with sudo, the redirection (>>) is not. It's run by the underlying hadoop user, who does not have permission to write to /etc/hosts. The fix is:

sudo sh -c 'echo -e "ip1 uri1" >> /etc/hosts'

This runs the entire command, including the stdout redirection, in a shell with sudo.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!