How to append a line at the end of /etc/sudoers file using shell script (without using pssh tool)

4.2k views Asked by At

I want to append a few lines at the end of /etc/sudoers file. Below is an example of lines I want to append.

nagios ALL = NOPASSWD: /bin/su - root -c /etc/init.d/crond status
nagios ALL = NOPASSWD: /bin/su - hadoop -c hadoop dfsadmin -safemode get
nagios ALL = NOPASSWD: /bin/su - hadoop -c klist

Can anyone suggest how to append this using a shell script?

2

There are 2 answers

0
codeforester On BEST ANSWER
cat >> /etc/sudoers << EOF
nagios ALL = NOPASSWD: /bin/su - root -c /etc/init.d/crond status
nagios ALL = NOPASSWD: /bin/su - hadoop -c hadoop dfsadmin -safemode get
nagios ALL = NOPASSWD: /bin/su - hadoop -c klist
EOF
0
PaSe On

One can also insert a string in one line without EOF formatting:

cat >> /etc/sudoers <<<'PaSe ALL=(ALL:ALL) NOPASSWD:ALL'