在启动时获取用户input

我有一个脚本,我需要在第一次启动安装后运行,要求用户input主机名并设置新的主机名。 什么是最好的办法呢? 现在我这样做:

在rc.local

openvt -s -w /opt/post_install_script 

post_install_script:

 #!/bin/bash NEW_HOSTNAME="$1" echo -n "Please enter new hostname: " read NEW_HOSTNAME < /dev/tty doing other stuff.. 

它的工作在Ubuntu 12上确定,但不要等待用户input,并继续在Ubuntu 16上启动。

我已经阅读了有关systemd systemd-ask-password但它不起作用。

有任何想法吗?

创build文件/etc/systemd/system/renamepc.service

 [Unit] Description=Hostname configuration DefaultDependencies=no Before=nss-user-lookup.target [Service] Type=oneshot ExecStart=/opt/script [Install] WantedBy=multi-user.target 

创build文件/ opt / script

 #!/bin/bash NEW_HOSTNAME=$(systemd-ask-password "Please enter new hostname: " --echo) change hostname code... 

更改脚本权限chmod u + x / opt / test