gpt4 book ai didi

linux - 在启动时执行交互式脚本并显示到默认的 tty 附加监视器屏幕

转载 作者:太空宇宙 更新时间:2023-11-04 12:36:30 25 4
gpt4 key购买 nike

我已将我的 Centos 6 配置为在每次启动时自动登录。

我修改了/etc/init/tty.conf 以实现此目的,效果很好。

/etc/init/tty.conf 的内容

stop on runlevel [S016]

respawn
instance $TTY
#exec /sbin/mingetty $TTY
exec /sbin/mingetty --autologin root $TTY
usage 'tty TTY=/dev/ttyX - where X is console id'

然后我配置了我的 ~/.bash_profile 来运行脚本。请参阅下面的内容。

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH


echo "This is one time" >/tmp/one.txt

正如您在上面看到的,我已将文本回显到文件/tmp/one.txt,文件中的预期文本应该只出现一次。但是由于某种原因,这个脚本被执行了 3 次。

如果我 tail -f/tmp/one.txt 下面出现在/tmp/one.txt 中。它显示脚本执行了 3 次。

tail -f /netboot/tmp/one.txt
This is one time
tail: /netboot/tmp/one.txt: file truncated
This is one time
tail: /netboot/tmp/one.txt: file truncated
This is one time
tail: /netboot/tmp/one.txt: file truncated
This is one time

我能做些什么来防止它多次执行,我只希望它运行一次就可以了。

感谢阅读这篇文章

最佳答案

我必须从/etc/init/tty.conf 文件中删除重生实例 $TTY。

修复/etc/init/tty.conf 之前看起来像这样。

stop on runlevel [S016]

respawn
instance $TTY
#exec /sbin/mingetty $TTY
exec /sbin/mingetty --autologin root $TTY
usage 'tty TTY=/dev/ttyX - where X is console id'

解决问题后。/etc/init/tty.conf 看起来像这样。

stop on runlevel [S016]


exec /sbin/mingetty --autologin root $TTY
usage 'tty TTY=/dev/ttyX - where X is console id'

这解决了我上面解释的问题。

关于linux - 在启动时执行交互式脚本并显示到默认的 tty 附加监视器屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41577166/

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