I need my app to connect to a remote server via ssh, and run terminal commands. As far as I know, this is a non-interactive connection. Which differs from the one you open a terminal by yourself. I'm getting some errors right now when my app runs terminal commands. I want it to act exactly like I myself running these commands. So how can I achieve this? I'm a programmer not a Linux expert though.
Asked
Active
Viewed 543 times
0
-
2Few things need to be clarified. I think "interactive" vs "non-interactive terminal" is not a useful distinction (if defined at all); there's "interactive" vs "non-interactive [*shell*](https://unix.stackexchange.com/q/4126/108618)". The differences you observed may be because tty is not allocated on the remote side. `ssh -t` or `ssh -tt` may help; or (local) `expect`, if you need to "type" input not-too-soon or so. Can you provide [mcve](https://meta.stackoverflow.com/a/367019/10765659)? You may omit "verifiable", but at least show us the commands you used and the errors you got. – Kamil Maciorowski Dec 08 '21 at 11:25
-
Thanks. I'm not using commands directly to connect to remote server. My app does it via a library. It can connect and run commands. I was wondering if something could be changed in the remote server after my app connects. right now I've set up my app to remove the line `[ -z "$PS1" ] && return` form `.bashrc` file. And it's working. I mean I get no more errors. But I don't know if it's a reliable solution. – james hofer Dec 08 '21 at 11:36
-
1Please see [this answer of mine](https://superuser.com/a/1616143/432690) to get context. The line you removed is a form of "twist number 3", you turned it off. Apparently your workflow needs some line(s) later in your `.bashrc` to be processed. It's possible some other line(s) shouldn't be processed, so the fact you entirely disabled the "twist 3" may bite you later. It may be good to identify the lines you need, re-enable the "twist 3" and place the needed lines before the "twist 3 line". Without seeing your `.bashrc`, the commands and the errors, it's hard to tell what the lines may be. – Kamil Maciorowski Dec 08 '21 at 21:20