I have a very simple shell script to stop the Apache server:

#!/bin/bash
sudo /usr/sbin/httpd -k stop

I named it "". When I run it from the command line, it stops Apache. However, when I double click the "" icon on the Desktop, I'm asked whether I want to run or display it, I pick "Run", but the Apache Server doesn't stop.

How do I get a script which successfully executes at the command line to run when clicked?

I'm running CentOS 2.16.0.

Dani AI

Generated

A focused addendum for that expands on replies from and .

The core issues are (1) how the file manager launches a script (no interactive terminal, different PATH) and (2) how privilege escalation behaves when there is no TTY. was right to flag permissions—make sure the file is marked executable in the file manager’s Properties or by checking its mode from the shell—however executable permission alone won’t solve the sudo/GUI problem. On many RHEL/CentOS installs sudo is configured to require a TTY, so a double-click launch that can’t prompt for a password will silently fail.

Practical options (choose one that matches the desktop and security policy in place):

  • Run the script in a terminal from the GUI: create a desktop launcher that sets Terminal=true so the password prompt and any output are visible. Example .desktop skeleton:
[Desktop Entry]
Type=Application
Name=Stop Apache
Exec=pkexec /full/path/to/script
Terminal=true
  • Use a graphical auth helper (modern: polkit/pkexec; older GNOME: gksu/gksudo) so a password dialog shows instead of relying on a TTY. That makes a double-click able to prompt for credentials.

  • For controlled environments, grant only the exact service-control binary passwordless sudo via visudo (restrict to the single full path). Example visudo entry:

alice ALL=(root) NOPASSWD: /usr/sbin/apachectl
Defaults:alice !requiretty

Use visudo to edit /etc/sudoers. Limit NOPASSWD to the specific executable and prefer a user-specific Defaults entry rather than disabling requiretty globally.

Final notes: ’s pointer to approaches for supplying a password from a GUI is relevant—prefer polkit/pkexec or a terminal-launched helper to avoid insecure password-handling code. ’s reply appears unrelated to this thread.

Recommended Answers

All 3 Replies

When you run from CLI, are you typing the command in the file or ./? It could be that your permissions are wrong on the file.

chmod u+x

should give your file execute permission for the owner.

This is a desktop icon problem, quite appropriate here, IMHO. The same sort of issue can occur in any multi-user OS.

package you can type in
internet ie trap17
or if ie is default you can type in internet
and if .com is default and you turned on short cmds then you can type in
i trap17 (or the bookmark name such as "i t17"

Yet another thing
For firefox you put
@start /b "firefox.exe" %*

For internet exlorer you only need to put in
@start /b "iexplore.exe" %*

There is a lot more that i can say but i don't have the time to put it all here
SNIP

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.