以普通用户的身份执行bash脚本

我正在尝试从一个普通用户作为根执行一个bash脚本。 背后的故事是我需要www数据用户能够杀死一个特定的过程。 为了避免让apache能够在进程上造成混乱,我创build了下面的bash脚本

#!/bin/bash PID=$(pgrep mono) kill -9 $PID 

为了能够执行这个,我做了一个apt-get install sudo ,然后用visudo在文件的底部添加下面一行

 myuser ALL= NOPASSWD: /path/to/script/foo.sh 

但是,当我login到myuser并尝试运行/path/to/script/foo.sh我收到以下错误-bash: /path/to/script/foo.sh: Permission denied

当前文件的权限如下

 -rwxr-xr-x 1 root root 48 Nov 7 12:11 foo.sh 

谢谢!

要使用sudo,你需要在命令前加上“sudo”。 即:

 $ sudo /path/to/script/foo.sh 

用rootlogin并执行以下操作:

 cd /path/to/script chmod u+x foo.sh ./foo.sh 

testing程序是否运行。 现在切换到myuser,

 su myuser 

并尝试再次运行该程序:

 /path/to/script/foo.sh