[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Issue with setting environment variables in Org-mode shell blocks vi
From: |
Michael Albinus |
Subject: |
Re: Issue with setting environment variables in Org-mode shell blocks via TRAMP |
Date: |
Sat, 28 Dec 2024 12:48:05 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Bartosz Kaczyński <bkaczynski@posteo.net> writes:
> Hello TRAMP users,
Hi Bartosz,
> I am using TRAMP to connect to a remote system over SSH and execute
> shell commands with sudo. However, the shell environment on the remote
> system does not load certain environment variables (specifically those
> defined in ~/.bashrc), which causes commands like systemctl --user
> daemon-reload to fail.
>
> My ~/.bashrc file in the serviceuser homedir:
>
> export XDG_RUNTIME_DIR=/run/user/$(id -u)
>
> Here is the Org-mode block I am trying to execute:
>
> #+begin_src shell :dir /ssh:user@remotesrv|sudo:serviceuser@remotesrv:
> systemctl --user daemon-reload
> #+end_src
>
> To work around this, I have tried forcing the remote shell to be
> interactive by modifying the TRAMP settings:
>
> (custom-set-variables
> '(tramp-encoding-shell "/bin/bash")
>
> (add-to-list 'tramp-connection-properties
> (list ".*"
> "remote-shell" "/bin/bash"
> "remote-shell-args" '("-i" "-c")))
"remote-shell-args" is not used in shell-command, if I read the code
correctly. You might try to modify tramp-sh-extra-args.
> I also tried sourcing ~/.bashrc explicitly in the Org-mode shell block,
> which works, but I'd prefer to have the environment variables set
> automatically without this extra step.
Yes, that's working just now.
> I’m wondering if this issue is related to the way TRAMP handles shell
> sessions or if it might be specific to how Org-mode executes code
> blocks. Do you have any advice on how I might ensure that environment
> variables like XDG_RUNTIME_DIR are automatically loaded when executing
> commands in Org-mode shell blocks via TRAMP?
Hmm, I don't know org-mode good enough. If you find a way to modify
tramp-remote-process-environment in time, it might help.
> Any guidance or suggestions would be greatly appreciated.
>
> Thank you for your time!
>
> bartk
Best regards, Michael.