1

I have a shell script using some sudo command. When I run this script from terminal - it asks me for password and runs with any problem. But when I try to run executable shell script form GUI (double click) it does not ask me for password - so does not work.

Example of my shell script:

c1=$(dmidecode -t 4 | grep ID | sed 's/.*ID://;s/ //g' | sha1sum | awk '{print $1}')

How to run script from GUI and pass all sudo commands with no problem?

muru
  • 197,895
  • 55
  • 485
  • 740
Geroge
  • 123
  • TL;DR: use gksudo or pkexec. – muru Jun 22 '16 at 10:18
  • @JonasCz the dupe is about getting a GUI password prompt, not running GUI applications - if OP wants to avoid having a password prompt at all, they should ask that – muru Jun 22 '16 at 10:27

1 Answers1

-1

You can pass the password to sudo from the standard input, like this:

echo 'yourpassword' | sudo -S yourcommand

Using -S tells sudo to read the password from stdin, which comes from the echo 'yourpassword' bit.

You could also edit visudo, so that sudo will never prompt for the password, either only for your specific comand, or always.

Warning: storing your password in plain text is an extremely bad idea

Jonas Czech
  • 4,017