0

I want to use When Gnome Scheduler to run this:

sudo service fancontrol start 

As "sudo" needs a password, how can I add it into the command, so that it can be run successfully? Each time Mint resumes after suspension, it needs to be run again.

1 Answers1

2

Instead of wondering how to get a password into a script I'd suggest modifying sudoers (or, even better [because cleaner], adding a separate file for this purpose to /etc/sudoers.d/).

Something like (assuming matthew's your username):

cat /etc/sudoers.d/fancontrol
matthew    ALL=NOPASSWD: /usr/sbin/service fancontrol start

Make sure it has the right permissions, and best to use visudo to edit it (that makes sure you don't have syntax errors in the file).

chmod 0440 /etc/sudoers.d/fancontrol
tink
  • 6,765
  • Do you mean using the command "chmod 0440 /etc/sudoers.d/fancontrol" on When Gnome Scheduler after adding the separate file "fancontrol" into the folder "/etc/sudoers.d/"? – Matthew Wai Feb 09 '19 at 09:35
  • I added the separate file "fancontrol" into "/etc/sudoers.d/". When I run "sudo service fancontrol start", it says the following: ">>> /etc/sudoers.d/fancontrol: syntax error near line 1 <<< sudo: parse error in /etc/sudoers.d/fancontrol near line 1 sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin". – Matthew Wai Feb 09 '19 at 12:09
  • I tried to use "sudo nemo /" to delete "fancontrol", but I got the same error. How can I delete it? – Matthew Wai Feb 09 '19 at 12:12
  • Actually, I fail to run any "sudo" command. What should I do? – Matthew Wai Feb 09 '19 at 12:17
  • I just booted from a Mint Live SD card. I selected "Show Hidden Files" and went to "/etc/sudoers.d/" on the HDD, but "fancontrol" was not there. I am now using Mint installed on the HDD, and "fancontrol" is still in "/etc/sudoers.d/". Why can't I find it via Mint Live? How can I delete it? – Matthew Wai Feb 09 '19 at 12:38
  • I just managed to delete "/etc/sudoers.d/fancontrol" via a Lubuntu Live SD card, and "sudo" has returned to normal on Mint. Why couldn't I use Mint to delete "fancontrol", which caused errors on Mint? I might have had to re-install Mint if it had not been for Lubuntu. – Matthew Wai Feb 09 '19 at 13:00
  • Glad you managed to recover. I assume you weren't using visudo? And no, the idea was to apply those perms to the newly created file in /etc/sudoers.d ... Not sure what went wrong for you there. – tink Feb 09 '19 at 17:10
  • Can you tell how to use "visudo"? I know nothing about it. – Matthew Wai Feb 10 '19 at 04:03
  • I just found the command "sudo visudo" but don't know how to use it on Terminal. – Matthew Wai Feb 10 '19 at 04:19
  • Do mean I should add the following lines via "sudo visudo"? If so, under which line should it be added? cat /etc/sudoers.d/fancontrol matthew ALL=NOPASSWD: /usr/sbin/service fancontrol start – Matthew Wai Feb 10 '19 at 04:40