【发布时间】:2017-07-03 11:50:40
【问题描述】:
我正在运行 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
主机名启动脚本:
#!/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:
Sample Boot Output 同时显示所有内容,并且不允许用户输入新的主机名。一旦显示这些行,系统就会继续进入登录屏幕。系统的期望行为将允许用户有时间输入新的主机名,然后显示之前提交的输入。
注意:脚本不是最终产品,它只是使用 rc.local 触发脚本的概念验证。
【问题讨论】:
-
这可能更适合Unix & Linux。