[英]Replace login prompt with interactive bash script on serial port linux
I am working on a CentOS box. 我正在使用CentOS盒子。
What I expect: To run my own CLI/setup on startup instead of login prompt on serial console (telnet). 我的期望:在启动时运行我自己的CLI / setup,而不是在串行控制台(telnet)上运行登录提示。
What I did so far:- I changed call to "agetty" command in serial.conf and serial-ttyUSB0.conf files under /etc/init/, as follows:- 到目前为止我做了什么: - 我在serial.conf中调用了“agetty”命令,在/ etc / init /下更改了serial-ttyUSB0.conf文件,如下所示: -
exec /sbin/agetty -n -l <path-to-my-custom-script> ........
My custom.sh script is:- 我的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
But when system boots, on a telnet session, I could only see the "Please choose to enter.." question on screen and after that I couldn't able to type anything on console. 但是当系统启动时,在telnet会话中,我只能在屏幕上看到“请选择输入...”问题,之后我无法在控制台上输入任何内容。
One more update: If I run the above agetty command on shell prompt as it is (say from ssh session), then it works fine on serial console (telnet). 还有一个更新:如果我在shell提示符上运行上面的agetty命令(例如从ssh session),那么它在串行控制台(telnet)上运行正常。 But, from the above startup scripts, it doesn't work.
但是,从上面的启动脚本,它不起作用。
Can anybody help me out with this? 有人可以帮我解决这个问题吗?
Thanks in advance. 提前致谢。
-Neo -Neo
Sorry I'm a few years late. 对不起,我迟到了几年。 Hopefully this will be of help for people searching for solution to this problem in the future.
希望这对将来寻求解决此问题的人们有所帮助。
The issue lies here: 问题在于:
-n, --skip-login Do not prompt the user for a login name.
-n, - skip-login不提示用户输入登录名。 This can be used in connection with -l option to invoke a non-standard login process such as a BBS system.
这可以与-l选项一起使用,以调用非标准登录进程,例如BBS系统。 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.
请注意,使用-n选项时,agetty不会从登录用户获取任何输入,因此无法确定连接的奇偶校验,字符大小和换行处理。 It defaults to space parity, 7 bit characters, and ASCII CR (13) end-of-line character.
它默认为空格奇偶校验,7位字符和ASCII CR(13)行尾字符。 Beware that the program that agetty starts (usually /bin/login) is run as root.
请注意agetty启动的程序(通常是/ bin / login)以root身份运行。
So you need to initialize the terminal yourself in the script you are replacing the login prompt with. 因此,您需要在要替换登录提示的脚本中自己初始化终端。 I found the settings below work well:
我发现下面的设置效果很好:
/bin/stty -F /dev/ttyO0 115200 cs8 sane
Remember to replace the baud rate and terminal name to your own. 请记住将波特率和终端名称替换为您自己的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.