I'm creating a shell script that needs to update the sudoers file. So basically I want to be able to append ":/usr/local/bin/" to the following text in /etc/sudoers:

secure_path = /sbin:/bin:/usr/sbin:/usr/bin

I need to use sudo in the command in order to gain the permissions to modify. Any idea how I can accomplish that?

link|improve this question
2  
Duplicate of stackoverflow.com/questions/323957/… – DKNUCKLES Apr 18 at 20:48
feedback

2 Answers

up vote 5 down vote accepted

So many ways!

The old standby is sed: sed 's/\(secure_path.*\)/\1:\/usr\/local\/bin/' /etc/sudoers

Scripts in vim can do advanced things as well. Any process you would type into vim can be saved to a vim script and played back.

The newest tool that's really handy for this is Augueas. It's often used with Puppet is structured around editing files in a structured manner. Thus, it's aware of context and hierarchies within a text file.

link|improve this answer
Thanks for the answer. However, I get the following when I try that command: sed: -e expression #1, char 22: unknown option to `s' – VinnyD Apr 22 at 22:49
@VinnyD Oops... I fixed up the escaped characters and quoting and tested it. Should work now. – Jeff Ferland Apr 22 at 23:26
feedback

best thing to use is : sed - stream editor for filtering and transforming text

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.