gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 11:18:47 25 4
gpt4 key购买 nike

我正在开发 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com