繁体   English   中英

rc.local可以在引导之前等待Bash脚本完成吗

[英]Can rc.local wait for Bash script to finish before booting

我正在运行Kali Linux的滚动发行版,并且已经开始编写一个由rc.local在引导时执行的脚本,该脚本将允许用户更新计算机的主机名。

rc.local中:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/root/hostnameBoot

exit 0

hostname启动脚本:

#!/bin/bash
# /etc/init.d/hostnameBoot

# Solution Added
exec < /dev/tty0

echo "Enter desired hostname:"
read hostname
echo "New hostname: $hostname"

#exit 0

如您所见,当前hostnameBoot提示用户输入新的主机名,然后将主机名返回给用户。

引导时,rc.local将执行脚本,但不会提示用户输入新的主机名。

样本引导输出:

- misc boot info - 
Enter desired hostname:
New hostname:

样本引导输出一次显示所有内容,并且不允许用户输入新的主机名。 一旦显示了这些行,系统便会继续进入登录屏幕。 系统的所需行为将使用户有时间输入新的主机名,然后使用先前提交的输入来呈现。

注意:该脚本不是最终产品,它只是使用rc.local触发脚本的概念证明。

引导脚本(包括rc.local )通常不会在交互模式下执行(即使用功能齐全的终端机,用户可以在其中输入数据)。 它们的输出重定向到控制台(因此您可以看到引导消息),但是输入很可能是/dev/null (因此read立即返回,没有任何内容可供读取)。

您将需要手动重定向读取以始终使用固定终端(例如, read </dev/tty0 ),或者打开虚拟控制台进行用户输入(例如, openvt -s -w /root/hostnameBoot )。 有关更多详细信息,请参见此答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM