Ask Ubuntu Asked by kairocks2002 on January 19, 2021
I’m trying to automate the installation of CUDA on an Ubuntu 18.04 VM template as part of the startup script. I’m very new to bash and cloud computing in general. When I run the command to install CUDA, mid-installation I am always prompted to choose a country and a language from a list of options by entering the corresponding ID numbers.
Basically, when I run:
sudo apt-get -y install cuda
I know I’m going to have to manually enter "31" and "1" for the install to complete. As a relative n00b at all this, my question is thus "How do I automate those inputs so I don’t have to manually type them in every time I spin up a fresh copy of this VM template?"
My initial approach was this:
printf "31n1n" | sudo apt-get -y install cuda
But this does not seem to work the way I expected it to. No input is autofilled.
My end goal is to have everything taken care of in one startup script that I don’t have to touch.
I appreciate any and all help, and I apologize if my question has been answered elsewhere (if it has, I’ve been unable to find it and would greatly appreciate being directed to it!)
Install expect
and write an expect script that answers the prompts. This will look something like this (warning - not tested in any way):
#!/usr/bin/expect
spawn sudo apt-get -y install cuda
expect "first prompt:"
send "31r"
expect "second prompt:"
send "1r"
wait
where you need to substitute appropriate actual prompts instead of "first prompt:" and "second prompt:".
Look here for more information about expect
:
https://www.slashroot.in/expect-command-tutorial-linux-example-usage
http://tcl.tk/man/expect5.31/expect.1.html
You may be also interested in autoexpect
, which can generate a script automatically by watching your interactive session:
Correct answer by raj on January 19, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP