Sudoers file permissions

twigg asked:

I’m trying to run the following command without the need for sudo:

echo 1 | sudo tee -a /sys/block/$hd/device/delete

The $hd variable changes dynamically from sdb -> sdi for each one of my HDD’s in my drive bay.

I added the following line to the sudoers file:

operator ALL=/sys/block/sdb/device/delete

But this didn’t make a difference its still asking for sudo password even if I run:

echo 1 | sudo tee -a /sys/block/sdb/device/delete

My answer:

Put your code in a script (you ARE writing a script, right?) and grant the user sudo access to the script.

It’ll probably end up looking something like this:

for kill_this_disk in /sys/block/sd[b-i]/device/delete
    echo 1 > $kill_this_disk

And, I hope you have good backups.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.