Mint 19.1: Bash scripts no longer work from desktop launcher
Linux MintThis forum is for the discussion of Linux Mint.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I realised I was repeating your original post to a considerable extent - I felt it might be useful to add weight that multiple users are suffering this issue.
But also you said in an earlier post :-
It makes sense that a script run from a launcher won't work if there is a read command (or a sudo command that requests a password via a read command), since there is no terminal from which to display a message and/or read a response. So the real question is why it worked before?
In the case of sudo, I'm speculating that it did NOT prompt for a password when run from a desktop launcher, but now it does. Alternately, because sudo retains the password for a small time frame, perhaps coincidentally I ran sudo (and entered a valid password) from a terminal, and then ran the desktop launcher script within the time frame?
I felt it might be useful to document my experience which is that sudo works perfectly and prompts for a password from inside a bash script invoked via a desktop launcher on Mint 19 and 17.3. It also works (and prompts) if the launcher itself invokes the entire script inside a sudo call. But neither case works with Mint 19.1.
you need to use pkexec instead of sudo (not together).
Do you even bother to read what has been posted? You keep suggesting things that have nothing to do with the problem. pkexec allows an authorized user to execute a program as another user. sudo grants a user root privileges so that the user can execute programs or scripts that require the permission of the root. My scripts (and those of others) need to execute certain commands as root. They do not need to run the entire script as root. pkexec is NOT a solution to the problem.
I realised I was repeating your original post to a considerable extent - I felt it might be useful to add weight that multiple users are suffering this issue.
Yes, you are correct. Thank you.
Quote:
I felt it might be useful to document my experience which is that sudo works perfectly and prompts for a password from inside a bash script invoked via a desktop launcher on Mint 19 and 17.3. It also works (and prompts) if the launcher itself invokes the entire script inside a sudo call. But neither case works with Mint 19.1.
That is useful. So, apparently sudo could prompt for a password without a terminal in earlier versions of Mint, but this capability has been removed in 19.1. Isn't progress wonderful?
Do you even bother to read what has been posted? You keep suggesting things that have nothing to do with the problem. pkexec allows an authorized user to execute a program as another user. sudo grants a user root privileges so that the user can execute programs or scripts that require the permission of the root. My scripts (and those of others) need to execute certain commands as root. They do not need to run the entire script as root. pkexec is NOT a solution to the problem.
You need to realize, the two things are exactly the same:
Code:
allows an authorized user to execute a program (like a script) as another user (for example as root).
grants a user root privileges so that the user can execute programs or scripts that require the permission of the root.
Rather than launching the script with pkexec, I tried replacing every occurrence of "sudo" in the script with "pkexec", and launching it with bash. Now, the script does prompt for a password (when the first pkexec is encountered), but if the wrong password is supplied, or "cancel" is clicked, it proceeds as if a valid password was provided. Conversely, when the correct password is provided, it prompts for the password every time a pkexec command is issued, rather than only the first time. This is unacceptable, and is NOT "exactly the same" as sudo.
If that were true, they would do exactly the same thing, which they do not.
No, they are definitely not the same. As I posted pkexec is more secure. Especially in case of GUI.
And you still did not explain why can't you just simply [try to] replace sudo (all occurrences in your scripts. One by one). What is the problem with this approach?
No, they are definitely not the same. As I posted pkexec is more secure. Especially in case of GUI.
You also posted "they are exactly the same", which is that to which I replied.
Quote:
And you still did not explain why can't you just simply [try to] replace sudo (all occurrences in your scripts. One by one). What is the problem with this approach?
Well, firstly, because when you suggested using pkexec, we were discussing LAUNCHING the program with gksu, so it certainly seemed you were suggesting LAUNCHING it with pkexec instead. And, secondly, as stated in my revised comment above, pkexec does NOT provide the same functionality as sudo, at least without extensive changes to profiles and scripts.
You also posted "they are exactly the same", which is that to which I replied.
I can't find that. But probably misunderstood something. pkexec is the replacement, the more secure version of sudo.
Quote:
Originally Posted by cdgoldin
Well, firstly, because when you suggested using pkexec, we were discussing LAUNCHING the program with gksu, so it certainly seemed you were suggesting LAUNCHING it with pkexec instead.
That is unfortunately what you assumed, I never told "launching with pkexec".
Quote:
Originally Posted by cdgoldin
And, secondly, as stated in my revised comment above, pkexec does NOT provide the same functionality as sudo, at least without extensive changes to profiles and scripts.
I don't think so. You can use the common commands with pkexec "as usual" (instead of sudo), but that is what you need to test.
On 01-02-19 @ 12:34 PM post #20, you wrote, "You need to realize, the two things are exactly the same:" How difficult was that to find?
Quote:
But probably misunderstood something. pkexec is the replacement, the more secure version of sudo.
Yes, you have apparently misunderstood the problem reported in the first post, and everything since. Whether or not pkexec is more secure is debatable, and it certainly does NOT provide the same functionality as sudo.
Quote:
That is unfortunately what you assumed, I never told "launching with pkexec".
Since we were discussing _launching_ with gksudo, and you suggested "use pkexec instead of sudo", it was the only logical assumption that we were still talking about launching.
Quote:
I don't think so. You can use the common commands with pkexec "as usual" (instead of sudo), but that is what you need to test.
What is the so that you don't think? I have described in detail several differences between pkexec and sudo that make it unsuitable for the application, and NOT a viable replacement. Why do you argue with facts?
Using the recommended syntax for running command under gnome-terminal works for me on Mint 19.1....
Perhaps you can explain how it works for you with a more detailed example, because I have no idea how you are using the command.
In my situation, I have a script which invokes sudo several times to perform commands with elevated privileges. The first instance of sudo asked for a password. The subsequent ones do not. This no longer works when launched from the desktop in Mint 19.1. If I launch it with gksudo (gksudo <pathtoscript>), it works as before, but then the entire script is running with elevated privileges, not just the commands prefixed with sudo, which is undesirable (although not critical if there are no errors in the script).
Is your "works for me" situation similar to that described, or are we comparing apples with oranges? If the former, please provide the exact syntax of gnome-terminal that "works for you". And, are you launching a script with gnome-terminal, or are you replacing the sudo commands with gnome-terminal?
Try setting the Exec path directly in your desktop file
Workaround I found calling mate-terminal directly from the launcher
Exec=mate-terminal -- path/do/your/script
You can edit your desktop file with vi. This issue had me going in circles for some time.
If you don't have mate installed you can do
sudo apt install mate-terminal
Then once installed start it and click on Edit then Profile Preferences to
set the parameters like font, colors, bell, cursor, etc.
Only certain versions of Linux require this. Ubuntu does not.
Hope this helps...
Update. It appears in Mint 19.2 it got fixed. Try a sudo apt update and
sudo apt upgrade then edit Exec in your desktop file. Be sure the mode
of your script file is 755. So it looks executable.
Exec=/path/do/your/script
Seems it works as expected.
Last edited by KenUnix; 12-17-2019 at 06:27 PM.
Reason: Typo
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.