• Willkommen im Linux Club - dem deutschsprachigen Supportforum für GNU/Linux. Registriere dich kostenlos, um alle Inhalte zu sehen und Fragen zu stellen.

Probleme mit sudo und export-Variablen in /etc/profile

Hi Leute!

Ich hab da mal ein seltsames Problem. Wenn ich mit sudo als Benutzer ein Skript öffnen will, stehen mir meine Variablen, die ich in der /etc/profile gesetzt habe nicht zur Verfügung:

In /etc/profile ist eine Variable deklariert:
Code:
export meinpfad="/opt/verzeichnis"

Mein Skript:
Code:
#!/bin/bash
#test.sh
echo $meinpfad

als root:
Code:
./test.sh            -Ausgabe--> /opt/verzeichnis

als benutzer1:
Code:
sudo ./test.sh    -Ausgabe--> nix!!!

meine /etc/sudoers
Code:
User_Alias test = benutzer1
Cmnd_Alias kommandos = /tmp/test.sh
test ALL=NOPASSWD:kommandos

Wo kann ich konfigurieren, dass bei sudo die export-Variablen auch genutzt werden können?

System: Debian Sarge

Vielen Dank im Voraus
Pinf
 
Hi,

Ich Denke, daß dein Problem darin besteht, das sudo eine neue shell öffnet bevor
das Kommando ausgeführt wird.
Schau Dir mal die -i Option and vielleicht hilft das ja.

-i The -i (simulate initial login) option runs the shell specified in the passwd(5) entry
of the user that the command is being run as. The command name argument given to the
shell begins with a - to tell the shell to run as a login shell. sudo attempts to
change to that user's home directory before running the shell. It also initializes
the environment, leaving TERM unchanged, setting HOME, SHELL, USER, LOGNAME, and PATH,
and unsetting all other environment variables. Note that because the shell to use is
determined before the sudoers file is parsed, a runas_default setting in sudoers will
specify the user to run the shell as but will not affect which shell is actually run.


Gruss,

Frodus
 
Poste bitte mal alle Defaults-Einträge aus der /etc/sudoers.

Und ändere deine /etc/sudoers mal wie folgt:
Code:
User_Alias    TEST = benutzer1, benutzer2

Cmnd_Alias   KOMMANDOS = /tmp/test.sh

TEST ALL = NOPASSWD: KOMMANDO

Defaults:TEST env_keep = "MEINPFAD VAR1 VAR2 VARX"

PS: Alias-Definitionen (und export-Variablen) schreibt man i.d.R. groß. :wink:
 
Oben