Bel in PuTTYwhen it is waiting for input?

2

I often have to download, update and build large projects due to which there is a long waiting period between 2 commands. The projects are stored and used on a linux machine, and i connect remotely to it using PuTTY.

Looking for a way to be alerted when a command is done, while i keep working on something else.

I am not expecting below approach, as the command itself may wait for input.

<command> && tput bel

Thanks.

wolfram77

Posted 2016-06-06T08:19:47.853

Reputation: 143

Answers

1

PuTTY doesn't know when a remote command is waiting for input. As far as the terminal (or the SSH client) is concerned, input can always be sent. (Even trying to guess based on shown text is futile since many progress displays are indistinguishable to a computer from input prompts.)

Given your requirements, the only option I can think of is a LD_PRELOAD library that prints a bell whenever any program tries to read from a tty device. Something like:

#define _GNU_SOURCE
#include <dlfcn.h>
#include <unistd.h>

ssize_t read(int fd, void *buf, size_t count) {
    static ssize_t (*real_read)(int fd, void *buf, size_t count);

    if (isatty(fd))
        write(fd, "\a", 1);

    if (!real_read)
        real_read = dlsym(RTLD_NEXT, "read");

    return real_read(fd, buf, count);
}

(Well, it doesn't work for any statically-linked binary, but close enough.)

Then again, if a command waits for input, then it is by definition not done, so the requirements are somewhat contradictory.

user1686

Posted 2016-06-06T08:19:47.853

Reputation: 283 655

i think you have written kind of a proxy function for read command. the command is a build script actually and when i run it, it asks for sudo permission in between when i have to enter the password. also every time a run a command i have to make sure i end it with tput bel otherwise i wont hear any bell. so there is no generic solution for putty? – wolfram77 – 2016-06-06T11:30:16.533

The read() libc function has nothing to do with the read shell command. As for sudo, export SUDO_PROMPT=$'\aEnter sudo password: ' – user1686 – 2016-06-06T11:47:54.570

my bad, i mean read() libc function only. But i am surprised that it is not possible. (many progress displays are indistinguishable to a computer from input prompts). Isnt it true that a program waiting on input would be waiting by a read from stdin in its main thread. Linux should be able to know that the program is indeed waiting for input, and not processing something.. If so is possible it should also be possible to pass on this information to PuTTY. – wolfram77 – 2016-06-06T15:30:03.270

Maybe all this is getting so complicated, and i should stick to tput. But i asked this question guessing someone might have an easier way. Thanks. – wolfram77 – 2016-06-06T15:30:43.067

0

As a 90% solution, you can tell your shell to echo a bell when a command completes. For instance, in bash, simply include \a in your PS1.

If you'd like a bell when the command stops to ask for input, a 99% solution is available in non-Linux Unixen: hit Ctrl-Y after running your command. Lacking support for that, though, try looking for program-specific configurations. For instance, in Vim, you can add norm \ to your .vimrc to echo a bell whenever it is launched.

twifkak

Posted 2016-06-06T08:19:47.853

Reputation: 149