linux - 在串口 linux 上用交互式 bash 脚本替换登录提示

标签 linux bash authentication console startup

我正在开发 CentOS 机器。

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

到目前为止我做了什么:- 我在/etc/init/下的 serial.conf 和 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 session 中,我只能在屏幕上看到“请选择输入..”问题,之后我无法在控制台上输入任何内容。

还有一个更新: 如果我按原样在 shell 提示符下运行上面的 agetty 命令(比如从 ssh session ),那么它在串行控制台 (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

请记住将波特率和终端名称替换为您自己的。

关于linux - 在串口 linux 上用交互式 bash 脚本替换登录提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28035559/

相关文章:

linux - Linux ShellScript 问题

javascript - 为登录表单设置 cookie

angularjs - 登录后symfony angularjs InsufficientAuthenticationException

python - subprocess.Popen() 管道问题

c - 向stderr写入数据使程序成为守护进程后退出

PHP Mailer 在 Linux 中发送电子邮件太慢

php exec() 适用于某些调用,不适用于其他类似的调用

bash - 为什么 docker-compose exec 仅适用于某些服务?

javascript - 如果未登录,则限制对 js 文件的访问

linux - 为什么open函数在linux下没有O_SEARCH标志?