我正在嘗試運行一個更改背光的腳本,但需要使用鍵盤快捷鍵的 root 權限。由於我不想每次更改亮度時都輸入密碼,因此我想在 sudoers 檔案中為該腳本添加例外。然而我的嘗試都沒有成功。請注意,我自己沒有編寫這個腳本,因此並不完全理解它(但對於大多數部分,我確實理解)。
額外資訊:
-我在 .bashrc 檔案中為腳本建立了一個別名:
alias backlight='sudo ./.config/Scripts/backlight.sh'
-我從腳本中刪除了 sudo 命令:
#!/bin/bash
# base dir for backlight class
basedir="/sys/class/backlight/"
# get the backlight handler
handler=$basedir$(ls $basedir)"/"
# get current brightness
old_brightness=$(cat $handler"brightness")
# get max brightness
max_brightness=$(cat $handler"max_brightness")
# get current brightness %
old_brightness_p=$(( 100 * $old_brightness / $max_brightness ))
# calculate new brightness %
new_brightness_p=$(($old_brightness_p $1))
# calculate new brightness value
new_brightness=$(( $max_brightness * $new_brightness_p / 100 ))
# set the new brightness value
(sudo) chmod 666 $handler"brightness"
echo $new_brightness > $handler"brightness"
-這些是我正在嘗試的行,將它們添加到 sudoers 文件的末尾:
ALL ALL=(ALL) NOPASSWD: /home/sepseel/.conf/Scripts/$
#ALL ALL=(ALL) NOPASSWD: /bin/chmod
-我的系統目前運行的是 ubuntu 16.04,帶有 te i3wm,因此我在 shurtcut 的 i3 配置文件中包含以下內容:
bindsym XF86MonBrightnessUp exec "sudo ./home/sepseel/.config/Scripts/backlight.sh +10"
bindsym XF86MonBrightnessDown exec "sudo ./home/sepseel/.config/Scripts/backlight.sh -10"
提前致謝。