My self-documenting maintainance scripts, where I document how systems have been setup, I need to execute stuff as sudo/root and want the results automatically added to the document. But for safety reasons on the target system root has login disabled. I have to connect via an admin-user, which then can sudo stuff.
in my emacs init.el this adds bash execution:
;; allow org mode bash execution
;; --------------------------------------
(org-babel-do-load-languages 'org-babel-load-languages '( (shell . t ) ) )
Then in my document I have e.g. this bash / shell piece:
#+BEGIN_SRC bash :dir /sudo:adminuser@fresh_installed_computer:~/ :results output
parted /dev/sda "unit GiB" "print free"
parted /dev/sda "unit s" "print free"
#+END_SRC
The error message is:
Host 'fresh_installed_computer' looks like a remote host, 'sudo' can only use the local host.
See Org-Mode Manual: 15 Working with Source Code
Using Debian Stretch with Emacs 24.5.1 on the local machine, the remote machine is about to become debian buster fresh install.
UPDATE
When executing
#+BEGIN_SRC bash :dir /ssh:adminuser@fresh_installed_computer|sudo:fresh_installed_computer:~/ :results output :session
echo "user $USER"
#+END_SRC
The status line holds "Opening connection for root@fresh_installed_computer using sudo... \" and then waits forever
Interestingly: when I add the actual IP address like this, it suddenly works as expected:
#+BEGIN_SRC bash :dir /ssh:adminuser@fresh_installed_computer|sudo:XXX.XXX.XXX.XXX:~/ :results output :session
echo "user $USER"
#+END_SRC
#+RESULTS:
: user root
ssh to adminuser@fresh_installed_computer and there pinging works, so name resolving is up.
ping fresh_installed_computer
Any explanation, or do I need to stick with magic number fixed ip adress in my document?
UPDATE 2
The issue with resolving hostname vs IP adress could be solved by clearing tramp proxy caches:
M-x tramp-cleanup-all-connections
M-: (setq tramp-default-proxies-alist nil)
Now all works fine! Thx
:dir /ssh:adminuser@fresh_installed_computer|sudo:localhost:~/
or:dir /ssh:adminuser@fresh_installed_computer|sudo:root@fresh_installed_computer:~/
work instead?:dir /sshx:adminuser@fresh_installed_computer|sudo:fresh_installed_computer:~/
work? Note the extrax
insshx
....|sudo:localhost:
-- that's once again going to create a dangerous proxy on Emacs versions < 27.M-x tramp-cleanup-all-connections
andM-: (setq tramp-default-proxies-alist nil)
and see whether that changes anything? (Mostly I'm wondering whether earlier attempts had left a dodgy proxy in place, such that it was trying to proxyroot@fresh_installed_computer
to somewhere else.)