Home > shell scripting > Live-session shell daemon

Live-session shell daemon

September 28Hits:1


I need software that runs a daemon server and hosts an interactive shell program as a subprocess. The software should also include a client program that connects to the daemon server and provides PTY access to the hosted subprocess. I also need to be able to send lines to the hosted subprocess's STDIN and read it's STDOUT from scripts(JSON/XML RPC is preferable, but I can also work with standard HTTP(e.g. REST?) or a command line util that comes with the software).


I work in Linux and use Vim as my development environment. The project uses Waf as a build system(which means the noise/signal ratio in the output is skyrocketing). The project needs a specific Linux configuration to build and run - which means either a virtual machine on my local computer or a remote compilation server.

This means I need SSH, and since I'm using Vim writing shell scripts to build and run projects is a second nature.

Attempt #1: SSH with command

This is the straightforward solution: run ssh with a compound command that cds to the project's folder and runs waf to configure/build/clean the project, or the whatever is required to run it.

The problem

Waf creates a ridiculously large amount of noise, making it hard to read the error messages when build fails. Due to Vim's poor terminal emulation, I can't copy the result to a Vim buffer(to parse it my own way), and I can't continue using Vim until I close the shell command's result.

The output is also too long to display all at once on the screen, so I need to continue scrolling tons of useless Waf output every time I build.

Reading the result to a buffer directly(r !ssh...) or using a third party shell plugin will be too cumbersome for regular use, since I don't need all that info when the build succeeds.

Attempt #2: Abusing tmux

This is what I'm currently using. I run an SSH session in a tmux window, and use tmux send-keys to build and run from a script. I'm using a dual monitor setup where the laptop's small monitor shows Konsole with the tmux session that runs ssh, and the larger external screen shows Vim with the code. It's hard to read the exact output, but I can easily see that the build is running and notice when it fails, and I can copy the output to a Vim buffer where I can parse it.

The problem

The main problem is that I have to copy the output to a Vim buffer manually. Reading the output of the last command is something I would like to automate, and use in scripts that can parse it.

Another problem is that I can't connect to the tmux session from inside Vim. Neither the built-in terminal emulator nor any of the terminal emulator plugins available can run a TUI application like tmux.

Attempt #3: Abusing Supervisor

Supervisor allows me to run and control other programs as daemons. It runs these programs as it's own subprocesses, so it has full access to their STDIN, STDOUT and STDERR. It has the fg command for opening an interactive session into these programs, and has an XML RPC service that allows me to send stuff to these programs' STDIN and read their STDOUT and STDERR.

Supervisor could have been perfect for me, but there is one problem that makes it unusable for my case:

The problem

Supervisor was never meant for running interactive shell programs - it does not support PTY at all! When I try to run Bash I can run commands but I don't get the prompt(which means Bash can't tell that STDIN is pending - an PTY feature AFAIK). ssh does not work at all - not when I invoke it directly and not when I invoke it from Bash - I simply get an error Pseudo-terminal will not be allocated because stdin is not a terminal. - and then my commands do nothing and I have to stop the process.


Does anyone know a program that can do what I want? Something like Supervisor with PTY support - or a way to make Supervisor itself support PTY - would be great.


Maybe GNU Screen (similar to tmux) could be of use to you.

It allows you to write a running log of a window (by either pressing CTRL-a followed byH in an attached session, or by invoking screen with -L). You could then use that screenlog.n to get the waf output into a VIM buffer in an (semi-)automated fashion.

Alternatively you can dump the output of a running, but detached session to STDOUT using screen -X hardcopy /some/file. I'm not sure if the scrollback buffer will be included in that dump though.

If you want to review the output interactively, you can also scroll inside a screen session: In an attached session, access the scrollback buffer by entering copy mode with CTRL-A, followed by [. You can then scroll up/down using CTRL-u and CTRL-d. To exit copy mode again, press ESC.

Related Articles

  • Live-session shell daemonSeptember 28

    TLDR I need software that runs a daemon server and hosts an interactive shell program as a subprocess. The software should also include a client program that connects to the daemon server and provides PTY access to the hosted subprocess. I also need

  • Run remote shell daemon as non root user with tab-completionApril 18

    I need to run any "remote shell daemon" (ssh, telnet, netcat, socat... I don't mind) as non-root user. The remote shell should provide tab-completion and I want to be able to browse history using arrows. I am currently using a netcat-based solut

  • What triggers notifications of the form "Bell in session Shell" in KDE?May 20

    I'm running KDE on Debian Testing. From time to time, programs running in a terminal (Konsole) trigger system notifications of the form "Bell in session Shell". What triggers these notifications? Note: I'm not asking how to disable them - I know

  • Controlling tty / terminal output from other session / shellMay 15

    We are told that a tty can control at most one session and furthermore that ttys can be controlled not to allow background process groups within its controlled session to write or read from it, the former being controlled by the TOSTOP option. Howeve

  • Can Process id and session id of a daemon differ?December 19

    As far as I understood from different articles and here , a daemon has the following features: Parent Process ID should be 1. No terminal should be associated with the process. The process id, session id and process group id of the process should be

  • Why is my default shell from /etc/passwd not started by terminals in a Unity session?

    Why is my default shell from /etc/passwd not started by terminals in a Unity session?August 18

    I'm trying to set fish as my default shell. It's installed on the system through apt-get and is listed in /etc/shells: > which fish /usr/bin/fish > grep fish /etc/shells /usr/bin/fish I used chsh to switch from Bash to fish: > chsh -s /usr/bin/fi

  • Bash shell: how to reconcile portable configuration files and GUI terminal start-up types (login or interactive)?December 2

    In an attempt to "properly" implement a standard configuration of my preferred shell, bash, for use across multiple platforms, I've come across some confusion when dealing with terminals that are inconsistent with their choice of shell start-up

  • Open a screen session inside a certain user on boot Ubuntu Server LinuxJanuary 5

    I currently have a private server which I test my web apps on which runs Ubuntu Server 10.04 I also host a few game servers (rather than having wasted CPU time :-D) for some of my friends. These game servers I run in the game user account and each on

  • What program starts dbus-daemon?October 29

    What program starts the per user session dbus-daemon process in GNOME 2 and GNOME 3 (presumably via dbus-launch)? I would like to know because I would like to add a directory to the list of directories that dbus-daemon checks for .service files. (Obv

  • How do I write a login daemon?January 20

    There are many guides to the steps for correctly launching a daemon process, such as Stevens' chapter in Advanced Programming in the UNIX Environment. There is less agreement on what steps should be taken after daemonizing, going the other way: launc

  • On MacOS setting zsh as shell using chsh does not change $SHELLNovember 26

    chsh -s /usr/local/bin/zsh The abover changes my default shell to ZSH, however even after starting a fresh session $SHELL is still set to /usr/local/bin/fish, my previous shell. So if I do exec $SHELL it starts a fish shell not zsh. I already looked

  • Sublime Text 2 R Build System (source file, send selection to interactive session)January 21

    The following is the description of the R build system I am using (very happy) with Sublime Text 2 on linux (Crunchbang). With it, I am able to: to source the current file.R to an interactive R session; to send the current selection to an interactive

  • Why does bashrc check whether the current shell is interactive?January 25

    On my Arch install, /etc/bash.bashrc and /etc/skel/.bashrc contain these lines: # If not running interactively, don't do anything [[ $- != *i* ]] && return On Debian, /etc/bash.bashrc has: # If not running interactively, don't do anything [ -z &qu

  • how to login a user using shell script [on hold]February 8

    In my computer i have two user(tiger,jenk) now i want to create a shell script for login user "jenk" from user "tiger" i m try this code [[email protected] mytask]$ echo -e "IncorrectPassword\n" | su jenk Password: su: Authent

  • How to install source rpm(src.rpm) in fedora?November 6

    How to install source rpm(src.rpm) in fedora? When i try to rebuild spec file after install package(for example openssh) with sample command : rpmbuild -ba openssh.spec I get folow message and not complet build Executing(%prep): /bin/sh -e /var/tmp/r

  • Execute rsync command over ssh with an ssh agent via crontabDecember 9

    i have a cronjob: 0 9 * * * rsync -a mydir remote_machine: i installed this with 'crontab -e'. i have an ssh-agent running, and when i execute the rsync command itself it works w/o any user interaction or password entry, but the cronjob fails with th

  • Source .profile and .bashrc on ssh login without ttyAugust 30

    How do I make sure ssh sources .profile and .bashrc on login without tty? I have a Mac (10.6.8) that I'm using for various UNIX-y tasks like hosting git repositories. I have remote login enabled via the System Preferences "Sharing" pane. When I

  • Is there any way to have console (rogue) mode programs take over only part of the terminal screen?January 19

    I like the command line because it preserves the context of what I'm doing. But if I use a "rogue" mode program like vi or less, the whole screen gets taken over. Is a middle way possible, where the console mode program takes over only half the

  • What happens under the covers to log me in and start up Unity or another Graphical User Interface?June 13

    When there's trouble, it might be good to understand what happens under the covers to sign a user into a GUI session and get a Unity (or other window manager) to bring up a desktop. --------------Solutions------------- How a desktop user GUI session

  • What are the initialization scripts that are executed when logging into Ubuntu? June 13

    When there's trouble, it might be good to understand what happens under the covers to sign a user into a GUI session and get a Unity (or other window manager) to bring up a desktop. --------------Solutions------------- How a desktop user GUI session

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.439 s.