我正在为我的学生分发VM,以进行初学者编程课程。为了提高速度,我没有让他们从头开始安装Ubuntu,而是打算给他们一个可以直接运行的完全设置的映像。
为了进行设置,我给了它一个牺牲的主机名,用户名和密码。当学生起床并跑步时,改变它的最干净的方法是什么?
我已经了解了这个要点,它的主机名进度有些不可靠,但是用户名阻止我更改它。
我希望这是尽可能简单的过程,因为这应该在他们的第一个实验室中进行。
我应该采取完全不同的方法。我愿意接受所有建议。
#!/bin/bash
clear
toilet " CODE1161 " --metal --font future
echo ""
toilet "Let's get started!" --metal --font future
echo ""
echo "We need to make this computer be YOURS"
echo "We need a name for you and your computer, make it short or it'll take up a lot of space."
echo "My computer is called um and my name is ben, so I get ben@um:~$ as my command prompt."
echo ""
read -p "Enter a name for your computer:" compname
read -p "Enter your name: " username
echo ""
toilet "$username@$compname~$" --gay --font wideterm
echo ""
echo "What do you think? If you hate it, press ctrl+c and do this again"
read -p "otherwise, just press enter." sacrificial
# set the host name, in a million places, for some unknown reason.
echo "1"
sed -i "/127\.0\.1\.1\s*vc/ { c \
127.0.1.1 $compname
}" /etc/hosts
echo "2"
sudo hostname -b $compname
echo "3"
sudo hostnamectl set-hostname $compname
echo "4"
sudo groupadd $username
echo "5"
sudo usermod -d /home/$username -m -g $username -l $username ben
expect
过一个交互式过程,并使它成为非交互式。基本上,使脚本expect
具有一定的输出并在脚本中已经知道响应。Ben想要等待用户输入并基于它执行命令。当然,我每天至少错一次,所以可能是这种情况。
expect
- admin-magazine.com/Articles/Automating-with-Expect-Scripts