How to make my script run with two clicks a command that contains sudo?
I have a very simple script, similar to this:
#!/bin/bash
#Seleciono o diretório onde se encontra o arquivo para execução
cd '/home/vmi/Área de Trabalho/TesteComandosNoLinux'
#Executo meu software
mono my-program.exe
I have found that I need my software to run as administrator for some functionality to work properly.
This script is run with two clicks to make it as user friendly as possible.
I'd like to keep running with two clicks, but I couldn't create (or find a script) like that.
2 answers
Hello! Change the group of your bash to sudo. Doing so will run with administrator powers. In Linux Mint for example it is possible to right-click and properties, in the "Permissions" tab. If you prefer via command:
Chown [options] [new_owner] [: new_group] file
Example (in terminal):
Chown valmor: sudo arquivo.sh
Will change the properties. If you need powers remember to use sudo to apply change
Sudo Chown valmor: sudo arquivo.sh
What I did was edit the file/etc / sudoers
Add at the end of the file:
user ALL=(ALL) ALL
user ALL=(ALL)NOPASSWD:path/do/meu-segundo-Script.sh
user ALL=(ALL)NOPASSWD:path/do/mono
user ALL=(ALL)NOPASSWD:path/do/meu/executável
The user password is required for my script to run with ./meu-segundo-Script.sh
.This does not happen when the script runs with sudo ./meu-segundo-Script.sh
, but I did not find an equivalent way to do sudo ./meu-segundo-Script.sh
with two clicks.
The resolution was to create a script that calls my script that does not need a password when executing the command sudo.
Meu-primeiro-Script.sh:
#!/bin/bash
cd '/home/vmi/Área de Trabalho/MinhaPasta'
sudo meu-segundo-Script.sh
Meu-segundo-Script.sh :
#!/bin/bash
sudo mono my-program.exe