visudo entry in one script
Hi Linux Guru's
I'm just wondering if creating for an entry to /etc/sudoers using "visudo" is possible under 1 script? It just happened I messed up /etc/sudoers using cat the >> /etc/suders and forgot to place "#" in in comment line. here is what I intended to insert on /etc/sudoers if ! grep -Fqi '# pogi is enabled' /etc/sudoers; then echo "# pogi is enabled" >> /etc/sudoers; echo "pogi ALL=(ALL) NOPASSWD:/opt/papa/bin/restart_pogi.sh" >> /etc/sudoers; echo "# oat entry ends" >> /etc/sudoers; else exit fi I just saw using visudo is validating the /etc/sudoers if the entry is invalid or can cause a corruption. Can you post me an example alternative on updating the sudoers using visudo command? |
Hi,
you could make your script edit a copy of /etc/sudoers, then use visudo to validate it before copying it to /etc/sudoers. Eg something like Code:
cp /etc/sudoers /tmp/sudoers.edit Evo2. |
Quote:
|
you cant directly edit the file sudoers file with cat >> /etc/sudoers or echo "blah blah" >>/etc/sudoers not even with sudo permissions because the redirection is carried out by the shell and by then the permissions will be dropped.
however if you are doing this with script, you can run Code:
"echo "blah blah" >>/etc/sudoers" with sudo <scriptname.sh> EDIT: evo2's method is better: Code:
using visudo -c -f /etc/sudoers.temp |
All times are GMT -5. The time now is 02:57 AM. |