0

I want to add this command timestamp=20 at the end of visudo file which will increase the sudo time for 20 min. This way I'll be able to use my bash script to install many applications. After I am done, I want to delete the same command from the visudo file.

My question might look trivial, but since visudo needs permission to edit so I don't know how to use to sed in a file that needs permission

Here is what I came with:

echo -e "add the timestamp" | sudo tee -a /etc/sudoers #This will add the timestamp command
sed '31,35' /etc/sudoers #This will remove the timestamp command

The first command works perfectly. However, running the second command shows this error:

sed: -e expression #1, char 5: missing command

Any suggestions or modifications I can use ??

2
  • 1
    The error message you posted indicates that the "d" was not there when you ran the sed command, but the answer you posted below makes the file be edited in-place. – dannysauer Feb 19 '14 at 21:48
  • Further, you need to add "timestamp_timeout", not "timestamp". And the sed should really delete one line matching "Defaults timestamp_timeout=20", not five lines from the file. This whole scenario is suspect. – dannysauer Feb 19 '14 at 21:50
0

Ok, I solved this problem. I added the option -i and d letter after the number 35. The numbers 31 and 35 meanse that sed will delete everything between between line number 31 and line number 35.

I also added the command sudo so I can use sed in files that need permission...

Here is the final command:

sudo sed '31,35d' -i /etc/sudoers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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