6

I searched and found similar questions but none were specific enough or solved my issue. An example would be this question Starting remote script/terminal based programs through ssh gives error (Error opening terminal: unknown.) which I am not using ssh so -t will not help.


Running webmin, has been fine for months and now I get this error.

Basically when I type nano or vi into terminal, I get the error "Error opening terminal: unknown."

[user@host ~]# nano
Error opening terminal: unknown.
[user@host ~]# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial
[user@host ~]# nano
Error opening terminal: unknown.

[user@host ~]# 

How do I fix "Error opening terminal: unknown." on Ubuntu 16.04.3 LTS running webmin?

New information:

  1. When I try running vi or nano directly on the server instead of using webmin or ssh to remote in, it works. Could this just be a problem with webmin?
  2. When I examine the environment variables it say's TERM=linux which is consistent with my other server which is running all the same software.

4 Answers 4

9

Try to run /bin/bash, I think it will allocate pseudo tty

Also try: TERM=linux then run nano

2
  • [user@host ~]# /bin/bash [user@host ~]# nano Error opening terminal: unknown. [user@host ~]# TERM=linux [user@host ~]# nano Error opening terminal: unknown. [user@host ~]# export TERM=linux [user@host ~]# nano Error opening terminal: unknown. [user@host ~]#
    – Stuperfied
    Nov 10, 2018 at 0:33
  • I have no more ideas, looks like webmin not being able to run ncurses based applications
    – LeonidMew
    Nov 10, 2018 at 1:16
2

Webmin terminal is not interactive yet. In-fact, it's a command line interface.

You can read more about it, we discussed it quite a lot.

It's in our todo to make it interactive.

2

I encountered this problem when I was trying to edit files inside the initramfs. This was the only thread I found so instead of hunting for another fix, I wrote a python script to make a simple text editor that works inside the initramfs (and other feature poor terminals)

It's pretty simple, only displays one line at a time so you press up and down to change lines and left and right to move the cursor and enter to save. Nothing fancy, but it seems to work okay for quick edits.

It requires only the readchar module: python3 -m pip install readchar

#!/usr/bin/python3
#Edit a text file inside the initramfs (when other text editors don't work)
'''Compile with: 
libgcc=$(find /lib -name libgcc_s.so.1 | head -n 1)
libutil=$(ldd /usr/bin/python3 | grep libutil | cut -d ' ' -f 3)
pyinstaller --onefile editfile.py  --add-data="$libgcc:." --add-data="$libutil:." --hidden-import readchar
'''
import shutil, sys, readchar


'''
Allow user to edit a line of text complete with support for line wraps and a cursor | you can move back and forth with the arrow keys.
lines = initial text supplied to edit
prompt= Decoration presented before the text (not editable and not returned)
'''
def text_editor(lines=[], prompt=''):

    term_width = shutil.get_terminal_size()[0] - 1
    line_num = 0
    if type(lines) in (list, tuple):
        multiline=True
    else:
        multiline=False
        lines=[lines]


    text = list(lines[line_num])
    ptr = len(text)
    prompt = list(prompt)
    space = [' ']

    c = 0
    while True:
        if ptr and ptr > len(text):
            ptr = len(text)


        copy = text.copy()
        if ptr < len(text):
            copy.insert(ptr,'|')
        copy = list(str(line_num)) + space + prompt + copy

        #Line wraps support:
        if len(copy) > term_width:
            cut = len(copy) + 3 - term_width
            if ptr > len(copy) / 2:
                copy = ['<']*3 + copy[cut:]
            else:
                copy = copy[:-cut] + ['>']*3 

        print('\r'*term_width+''.join(copy), end=' '*(term_width-len(copy)), flush=True)

        if c in (53,54):
            #Page up/down bug
            c = readchar.readkey()
            if c == '~':
                continue
        else:
            c = readchar.readkey()  


        if len(c) > 1:
            #Control Character
            c = ord(c[-1])

            #Save current line on line change
            if c in (53, 54, 65, 66):
                lines[line_num] = ''.join(text)

            if c == 65:     #Up
                line_num -= 1
            elif c == 66:   #Down
                line_num += 1
            elif c == 68:   #Left
                ptr -= 1
            elif c == 67:   #Right
                ptr += 1
            elif c == 54:   #PgDn
                line_num += 10
            elif c == 53:   #PgUp
                line_num -= 10
            elif c == 70:   #End
                ptr = len(text)
            elif c == 72:   #Home
                ptr = 0
            else:
                print("\nUnknown control character:", c)
                print("Press ctrl-c to quit.")
                continue
            if ptr < 0:
                ptr = 0
            if ptr > len(text):
                ptr = len(text)

            #Check if line changed
            if c in (53, 54, 65, 66):
                if multiline == False:
                    line_num = 0
                    continue
                if line_num < 0:
                    line_num = 0
                while line_num > len(lines) - 1:
                    lines.append('')
                text = list(lines[line_num])


        else:

            num = ord(c)
            if num in (13, 10): #Enter
                print()
                lines[line_num] = ''.join(text)
                if multiline:
                    return lines
                else:
                    return lines[0]
            elif num == 127:        #Backspace
                if text:
                    text.pop(ptr-1)
                    ptr -=1
            elif num == 3:          #Ctrl-C 
                sys.exit(1)
            else:
                text.insert(ptr, c)
                ptr += 1

#Main
if len(sys.argv) == 1:
    print("Usage: ./editfile <filename>")
    sys.exit(1)

f = open(sys.argv[1], 'r')
strings = f.read().split('\n')
f.close()
strings = text_editor(strings)

#Trim empty lines on end
for x in range(len(strings) -1,0, -1):
    if len(strings[x]):
        break
    else:
        strings.pop(-1)     


f = open(sys.argv[1], 'w')
f.write('\n'.join(strings)+'\n')
1

I had the same problem and it was solved in the following way:

sudo apt-get install rxvt-unicode
2
  • Any explanation about this? Nov 14, 2019 at 12:15
  • @davidbaumann - same; so I looked for *rxvt*, and there is a directory /usr/share/terminfo or /etc/terminfo/ with files like rxvt-256color and so on, and it turns out, it is installed by ncurses-bin_6.0+20160213-1ubuntu1_amd64, and that package likely gets pulled in by rxvt-unicode
    – sdbbs
    Oct 13, 2021 at 11:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .