Howto start an interactive script at ubuntu startup?
In my current solution, I'm using openvt
to start install_script
by adding the following line to \etc\rc.local
:
openvt -s -w /path/to/install_script
- It opens a new virtual terminal (besides the seven others available in Ubuntu Core 12.04 via
Alt-F[1-7]
). - The switch
-s
tellsopenvt
to switch to the new virtual terminal (without pressingAlt-F8
). - The Switch
-w
letsopenvt
wait for completion of the command/path/to/install_script
given toopenvt
. - Started this way, the script can get input from the user as usually by calling
read
. - After the script has finished, the virtual terminal is closed (no more switching to it using Alt-F8) and control is returned to the virtual terminal that was active before.
Related videos on Youtube
Carsten Scholtes
Updated on September 18, 2022Comments
-
Carsten Scholtes almost 2 years
Based on Ubuntu core 12.04, I have prepared a bootable DVD. After booting (to console only), I can login as a user and start a script for installation of an embedded device:
sudo install_script
In order to execute this script already at startup, I've added the following to
/etc/rc.local
in the image of the root filesystem on the DVD:/bin/bash -ic install_script
Since this script is executed unconditionally, I'd like to give the user some opportunity to bypass installation and get on to a login prompt. To that end, I'd like to use
read
in the install_script. Unfortunately, the script does not react to keyboard input when run from/etc/rc.local
. (There is no problem with the same script started from a shell after login).How can I get some user input at startup?
(Some thoughts:
- Maybe, I can somehow detect and connect a tty to
read
or to the script? I tried/bin/bash -ic install_script </dev/console
to no avail. - Maybe, there are more suitable options to
/bin/bash
or toread
? - Maybe, I could boot into a single shell of a certain user (maybe
root
, without logging in?) with.bashrc
callingsudo install_script
(avoiding password check for sudo?)? - Maybe, there exists a better place for calling the script?
- I would not like to separate the interaction (to occur earlier) and the install_script (e.g., by providing different boot options via isolinux and examining
/proc/cmdline
in the script) for the following reason: Before asking the user, I'd like to examine the system and give an overview of what exactly would happen during the install. At earlier stages of the boot process, the necessary information for the examination of the system may not yet be easily available.
)
-
Sos about 11 yearsHint: posting it here should help you more askubuntu.com
- Maybe, I can somehow detect and connect a tty to
-
Dave M about 11 yearsMore detail is needed to make this a useful answer
-
Mister Henson about 11 yearsSpent hours on this for building my own LiveCd with remastersys. Your answer FINALLY worked! Using profile.d for this is a BAD idea. Combined with autologin (default in some casper init script (25configure_init) and changed sudoers file for root context, you'll soon find yourself in a hell of multiple executed scripts (for each tty or the initialization of sub-shells [I'm not that sure about the second point]).