将登录提示替换为串行端口 linux 上的交互式 bash 脚本

Replace login prompt with interactive bash script on serial port linux

我正在开发 CentOS 机器。

我的期望:启动时 运行 我自己的 CLI/setup 而不是串行控制台 (telnet) 上的登录提示。

到目前为止我做了什么:- 我在serial.conf和/etc/init/下的serial-ttyUSB0.conf文件中更改了对"agetty"命令的调用,如下:-

exec /sbin/agetty -n -l <path-to-my-custom-script> ........

我的 custom.sh 脚本是:-

#!/bin/bash

LOOP_FLAG=0
while [ $LOOP_FLAG -eq 0 ]; do
        for TTY in /dev/ttyS0 /dev/tty0; do
            echo "Please choose to enter in 'setup' or 'cli'. (s/c)?  " > $TTY
        done
        read sc
        case $sc in
            [Ss]* ) LOOP_FLAG=1; <some-executable-cli-file-path>; break;;
            [Cc]* ) LOOP_FLAG=1; <some-executable-setup-file-path>; break;;
            * ) for TTY in /dev/ttyS0 /dev/tty0; do
                    echo "Please press 's' or 'c'." >$TTY
                done;;
        esac
done

但是当系统启动时,在 telnet 会话中,我只能在屏幕上看到 "Please choose to enter.." 问题,之后我无法在控制台上输入任何内容。

还有一个更新: 如果我 运行 上面的 agetty 命令按原样在 shell 提示符下显示(比如来自 ssh 会话),那么它在串行控制台 (telnet) 上工作正常。但是,从上面的启动脚本来看,它不起作用。

有人可以帮我解决这个问题吗?

提前致谢。

-新

对不起,我迟到了几年。希望这对以后寻找此问题解决方案的人有所帮助。

问题出在这里:

-n, --skip-login Do not prompt the user for a login name. This can be used in connection with -l option to invoke a non-standard login process such as a BBS system. Note that with the -n option, agetty gets no input from user who logs in and therefore won't be able to figure out parity, character size, and newline processing of the connection. It defaults to space parity, 7 bit characters, and ASCII CR (13) end-of-line character. Beware that the program that agetty starts (usually /bin/login) is run as root.

因此您需要在替换登录提示的脚本中自行初始化终端。我发现以下设置效果很好:

/bin/stty -F /dev/ttyO0 115200 cs8 sane

记得把波特率和终端名称换成你自己的。