3

I'm Using Centos version:

[sysadmin@backup-srv ~]$ cat /etc/redhat-release 
CentOS release 6.4 (Final)

I'm using this sudo version:

[sysadmin@backup-srv ~]$ sudo -V
Sudo version 1.8.6p3
Sudoers policy plugin version 1.8.6p3
Sudoers file grammar version 42
Sudoers I/O plugin version 1.8.6p3

I tried to setup notification mail for sudo, added this entry in bottom of sudo file using command visudo, but I am getting the following syntax error:

Defaults    mailto "babin@xxxxxxxxx.com"
Defaults    mailfrom "root@media.xxxxxxxxxxx.com
Defaults    mail_always on
Defaults    mailsub “*** Command run via sudo on %h ***”
Defaults    mail_badpass on
Defaults    badpass_message "Please Provide Correct Password"
Defaults    !lecture,tty_tickets,!fqdn,!syslog
Defaults    logfile=/var/log/sudo.log

This is the error I get while saving the sudo config file:

 121 Defaults        mailto "babin@xxxxxxxxx.com"
 122 Defaults        mailfrom "root@media.xxxxxxxxxxx.com
 123 Defaults        mail_always on
 124 Defaults        mailsub “*** Command run via sudo on %h ***”
 125 Defaults        mail_badpass on
 126 Defaults        badpass_message "Please Provide Correct Password"
 127 Defaults        !lecture,tty_tickets,!fqdn,!syslog
 128 Defaults        logfile=/var/log/sudo.log

The error is:

visudo: >>> /etc/sudoers: syntax error near line 121 <<<
visudo: >>> /etc/sudoers: syntax error near line 121 <<<

What to do now? How to setup the mail notification for Sudo version 1.8.6p3?

2

The problem is not in your line 121, but in your next line, with your line mailfrom "root@media.xxxxxxxxxxx.com. You forgot the closing double apostrophe. The good version were:

mailfrom "root@media.xxxxxxxxxxx.com"

The ground, why it was as a syntax error in line 121, and not in 122, is because the syntax analyser of the sudo and your text editor used a little bit different line ordering.

  • ok its corrected but still i cant get mail while executing sudo – Babin Lonston May 26 '14 at 8:47
  • @Lonston Then it is another problem - I suggest to ask this as a new question, maybe you get good answers. It is probably a local mail delivery problem and has nothing with sudo to do. If you make 2 different questions to solve the same problem, it is normally not a problem here (at least if they aren't duplicates, but in this case they aren't). And yet another suggestion: use the "shift", ".", "," characters are they are intended to, their rules are very simple but they make your text look much better. – peterh May 26 '14 at 8:51
  • Can you send mails from the command line with the mail command? (f.e. with the command echo "test mail"|mail root@media.xxxx.com) – peterh May 26 '14 at 8:54
  • yes i can send mail from command line and i have received to my personal email id from VPS – Babin Lonston May 26 '14 at 8:56
  • @Lonston It is really another problem, please make a new question. This question was about the syntax problem in your sudoers file, this was fixed - I really can't do anything with it that there is another problem in your system as well. But this problem can be just so simple fixed as this was. – peterh May 26 '14 at 8:59
0

I was seeing a similar Error, without the missing double quote, with the same version of sudo -- 1.8.6p3 on centos 6.5.

It looks like visudo wanted the equals syntax --

Defaults mailto = "xxx@xx.com"
Defaults mail_always

Specifying

Defaults mailto "xxx@xx.com"
Defaults mail_always on

Resulted in a syntax error for both entries.

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.