运行脚本时权限被拒绝

运行脚本时权限被拒绝

我正在尝试使用以下命令从 shairport-sync 服务运行脚本:

run_this_after_play_ends = "/home/pi/Watson/testmicend.sh"

/home/pi/Watson/testmicend.sh:

#!/bin/bash
python3 /home/pi/Watson/mprobot.py

出现此错误:

  from gopigo import *
Jul 27 11:02:39 raspberrypi shairport-sync[3923]:   File "/home/pi/Watson/gopigo.py", line 60, in <module>
Jul 27 11:02:39 raspberrypi shairport-sync[3923]:     bus = smbus.SMBus(1)
Jul 27 11:02:39 raspberrypi shairport-sync[3923]: PermissionError: [Errno 13] Permission denied

然后我将其添加到脚本中:

#!/bin/bash
sudo python3 /home/pi/Watson/mprobot.py

将 shiarport-sync 添加到 sudo 组

sudo usermod -aG sudo shairport-sync

使用 visudo 修改 etc/sudoers

%sudo   ALL=(ALL:ALL) ALL
shairport-sync ALL=(ALL:ALL) NOPASSWD:/home/pi/Watson/testmicend.sh

运行脚本得到:


Jul 27 11:08:14 raspberrypi shairport-sync[3923]: We trust you have received the usual lecture from the local System
Jul 27 11:08:14 raspberrypi shairport-sync[3923]: Administrator. It usually boils down to these three things:
Jul 27 11:08:14 raspberrypi shairport-sync[3923]:     #1) Respect the privacy of others.
Jul 27 11:08:14 raspberrypi shairport-sync[3923]:     #2) Think before you type.
Jul 27 11:08:14 raspberrypi shairport-sync[3923]:     #3) With great power comes great responsibility.
Jul 27 11:08:14 raspberrypi shairport-sync[3923]: sudo: no tty present and no askpass program specified
Jul 27 11:08:14 raspberrypi sudo[5271]: pam_unix(sudo:auth): conversation failed
Jul 27 11:08:14 raspberrypi sudo[5271]: pam_unix(sudo:auth): auth could not identify password for [shairport-sync]

我也尝试过在脚本中传递密码,但也失败了

相关内容