让我的脚本双击执行需要sudo特权的任务

问题描述 投票:0回答:1

我有一个非常简单的脚本,类似于此:

#!/bin/bash
#Select the directory where the file to run is located
cd '/home/vmi/Área de Trabalho/TesteComandosNoLinux'
#I run my software
mono my-program.exe

我发现我需要我的软件才能以管理员身份运行,某些功能才能正常运行。因此,我需要替换:

mono my-program.exe 

per:

sudo mono my-program.exe

此脚本运行with two clicks以使其尽可能易于使用。

我想通过两次单击来继续运行,但是无法创建(或找到一个脚本)那样。

linux bash shell mono sudo
1个回答
0
投票

我所做的是编辑文件/ etc / sudoers

在文件末尾添加:

user ALL=(ALL) ALL
user ALL=(ALL)NOPASSWD:path/of/my/second/script.sh
user ALL=(ALL)NOPASSWD:path/of/mono
user ALL=(ALL)NOPASSWD:path/of/my/executable

使用./my-second-script.sh运行脚本需要用户密码。使用sudo ./my-second-script.sh执行脚本不会发生这种情况,但是我发现没有等效的方法可以通过单击两次来执行sudo ./my-second-script.sh

解决方案是创建一个脚本,该脚本调用运行sudo命令时不需要密码的脚本。

my-first-script.sh:

#!/bin/bash 
cd /home/vmi/desktop/myfolder
sudo meu-segundo-Script.sh

my-second-script.sh:

#!/bin/bash
sudo mono my-program.exe
© www.soinside.com 2019 - 2024. All rights reserved.