How to make my script run with two clicks a command that contains sudo?

Asked

Viewed 312 times

1

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 found that I need my software to run as an administrator for some functionality to work properly.

That script is executed with two clicks to make it as user-friendly as possible.

I would like to keep running with two clicks, but I couldn’t create (or find a script) like this.

2 answers

1

Hello! Change your bash group to sudo. Doing so will run with administrator powers. In Linux Mint for example it is possible to do right-clicking and properties in the "Permissions" tab. If you prefer via command:

chown [options] [new_owner] [:new_group] archive

Example (at terminal):

chown Valmor:sudo file.sh

It will change the properties. In case you need powers remember to use sudo to apply the change

sudo chown View:sudo archive.sh

  • how do I do that ?

  • complemented the answer. Give a look!

  • Dude, I did this add the script to root and it didn’t work. I’ll do it again by consciousness-raising

  • Did it belong to the sudo group? When giving an ls -la the properties should be similar to this: -rwxr-Xr-x 1 Read more 149 May 8 2019 valmor_emulator.sh

  • I just did it again. The command was executed as described. By running ls -la I get -rwxrwxrwx Spectrum sudo 44 Nov 22 18:20 VMIS.sh.

  • But it hasn’t worked yet.

  • 1

    True, only for sure when you have run in the terminal, then appears the confirmation :/

  • I’ll show you a resolution that I found as a response option. That’s not where I’m going yet so I won’t mark it as solved. But you can help someone help me.

  • Now I am in doubt whether I should complete the question or post as an answer

Show 4 more comments

0


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

User password 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 found no equivalent way to do sudo ./meu-segundo-Script.sh two-click.

The resolution was to create a script that calls my script that does not need a password when running sudo.

my-first-script.sh:

#!/bin/bash 
cd '/home/vmi/Área de Trabalho/MinhaPasta'
sudo meu-segundo-Script.sh

my-second-script.sh :

#!/bin/bash
sudo mono my-program.exe
  • 1

    Wonderful. Thanks for sharing :/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.