我正在尝试运行一个脚本来更改背光,但需要使用键盘快捷键的 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,带有 i3wm,因此我的 i3 配置文件中有以下内容用于 shurtcut:
bindsym XF86MonBrightnessUp exec "sudo ./home/sepseel/.config/Scripts/backlight.sh +10"
bindsym XF86MonBrightnessDown exec "sudo ./home/sepseel/.config/Scripts/backlight.sh -10"
提前致谢。