How to get $DESKTOP_SESSION from sudo script?Root's .bashrc not executing on sudo -iExecute sudo without Password?Bash - Get Sudoer Username?Run sudo command within directoryError, even with sudo: “dd: failed to open ‘/dev/sda1’: Permission denied” (dd input piped from gzip)
How are Aircraft Noses Designed?
Is it safe to pay bills over satellite internet?
Advisor asked for my entire slide presentation so she could give the presentation at an international conference
First author doesn't want a co-author to read the whole paper
How to extract *.tgz.part-*?
Proving the order of quaternion group is 8
Company indirectly discriminating against introverts, specifically INTJ
Milk instead of water in bread
How can you tell apart the pronounciation at the end between the "meine" and "meiner" in the daily spoken situation?
Uniform Roe algebra of virtually abelian group is type I C*-algebra?
Does Darwin owe a debt to Hegel?
What's that funny "illo" I keep hearing in Southern Spain?
Did I Traumatize My Puppy?
Word for 'most late'
Why does Principal Vagina say, "no relation" after introducing himself?
Do more Americans want the Bidens investigated than Trump impeached?
Does immunity to fear prevent a mummy's Dreadful Glare from paralyzing a character?
I am often given, occasionally stolen, rarely sold, and never borrowed
Easy way of generating a 50-150W load @12V
Why do military jets sometimes have elevators in a depressed position when parked?
How can I communicate feelings to players without impacting their agency?
Why is technology bad for children?
Encountering former, abusive advisor at a conference
How does a ball bearing door hinge work?
How to get $DESKTOP_SESSION from sudo script?
Root's .bashrc not executing on sudo -iExecute sudo without Password?Bash - Get Sudoer Username?Run sudo command within directoryError, even with sudo: “dd: failed to open ‘/dev/sda1’: Permission denied” (dd input piped from gzip)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
The following sample script failed to get the desktop environment (DE) if executed with sudo. How to get the DE with a bash script executed with sudo?
#!/bin/bash
echo $DESKTOP_SESSION
echo $XDG_SESSION_DESKTOP
echo $XDG_CURRENT_DESKTOP
echo $SESSION
echo $MDMSESSION
echo $GDMSESSION
Tested on Xubuntu and Mate, the returns are empty.
user:~$ sudo bash '/path/sample.sh'
user:~$ bash '/path/sample.sh'
mate
mate
MATE
mate
user:~$
sudo desktop-environments
add a comment
|
The following sample script failed to get the desktop environment (DE) if executed with sudo. How to get the DE with a bash script executed with sudo?
#!/bin/bash
echo $DESKTOP_SESSION
echo $XDG_SESSION_DESKTOP
echo $XDG_CURRENT_DESKTOP
echo $SESSION
echo $MDMSESSION
echo $GDMSESSION
Tested on Xubuntu and Mate, the returns are empty.
user:~$ sudo bash '/path/sample.sh'
user:~$ bash '/path/sample.sh'
mate
mate
MATE
mate
user:~$
sudo desktop-environments
add a comment
|
The following sample script failed to get the desktop environment (DE) if executed with sudo. How to get the DE with a bash script executed with sudo?
#!/bin/bash
echo $DESKTOP_SESSION
echo $XDG_SESSION_DESKTOP
echo $XDG_CURRENT_DESKTOP
echo $SESSION
echo $MDMSESSION
echo $GDMSESSION
Tested on Xubuntu and Mate, the returns are empty.
user:~$ sudo bash '/path/sample.sh'
user:~$ bash '/path/sample.sh'
mate
mate
MATE
mate
user:~$
sudo desktop-environments
The following sample script failed to get the desktop environment (DE) if executed with sudo. How to get the DE with a bash script executed with sudo?
#!/bin/bash
echo $DESKTOP_SESSION
echo $XDG_SESSION_DESKTOP
echo $XDG_CURRENT_DESKTOP
echo $SESSION
echo $MDMSESSION
echo $GDMSESSION
Tested on Xubuntu and Mate, the returns are empty.
user:~$ sudo bash '/path/sample.sh'
user:~$ bash '/path/sample.sh'
mate
mate
MATE
mate
user:~$
sudo desktop-environments
sudo desktop-environments
asked May 13 at 17:07
NicolasSmithNicolasSmith
4221 gold badge4 silver badges17 bronze badges
4221 gold badge4 silver badges17 bronze badges
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
You need to pass -E
option to sudo
:
-E, --preserve-env
Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.
- see man sudo
(or online).
And run your script as
sudo -E '/path/sample.sh'
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1142924%2fhow-to-get-desktop-session-from-sudo-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to pass -E
option to sudo
:
-E, --preserve-env
Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.
- see man sudo
(or online).
And run your script as
sudo -E '/path/sample.sh'
add a comment
|
You need to pass -E
option to sudo
:
-E, --preserve-env
Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.
- see man sudo
(or online).
And run your script as
sudo -E '/path/sample.sh'
add a comment
|
You need to pass -E
option to sudo
:
-E, --preserve-env
Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.
- see man sudo
(or online).
And run your script as
sudo -E '/path/sample.sh'
You need to pass -E
option to sudo
:
-E, --preserve-env
Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.
- see man sudo
(or online).
And run your script as
sudo -E '/path/sample.sh'
answered May 13 at 17:18
N0rbertN0rbert
32.7k10 gold badges77 silver badges158 bronze badges
32.7k10 gold badges77 silver badges158 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1142924%2fhow-to-get-desktop-session-from-sudo-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown