Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

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

2 Answers 2

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.

share|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 '12 at 22:49
    
@VinnyD Oops... I fixed up the escaped characters and quoting and tested it. Should work now. –  Jeff Ferland Apr 22 '12 at 23:26

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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