Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Upstart script: Detect shift key down at boot

I want to add a question during boot. The user is supposed to make keyboard inputs and depending on those inputs, there is an if inside the script.

"Do you want X or Y?"

"Or simply wait 10 seconds to default to X."

share|improve this question

marked as duplicate by jokerdino, John S Gruber, Mitch, RolandiXor, RobotHumans Aug 23 '12 at 16:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Not sure I agree with that, as that is specifically "how to detect shift" – SpamapS Aug 6 '12 at 20:06
The question itself allowed more general solutions, although shift key was desired, and no answer was shift key only. Covers the same ground. – John S Gruber Aug 20 '12 at 2:36
up vote 2 down vote accepted

Its a bit tricky, but you can use plymouth to converse with the user while the system is coming up. This will only work if your job blocks the startup, because once runlevel 2 is reached and plymouth is terminated, you won't be able to interact anymore.

Basically you want to execute 'plymouth ask-question' or 'plymouth watch-keystroke' and the user will be prompted. So if you want to wait 10 seconds for the user, you'd have an upstart job like this (this is quite theoretical and untested!):

start on starting rc RUNLEVEL=[2345]
  myscript=`mktemp /tmp/`
  chmod 0750 /tmp/
  cat > $myscript <<EOF
# script is sent key pressed
cat > /tmp/keypresses.txt
kill -USR1 $$
  handle_usr1() {
    key=`cat /tmp/keypresses.txt`
    plymouth display-message --text="you pressed $key"
    exit 0
  trap handle_usr1 USR1
  plymouth watch-keystroke --command=$myscript --keys="ABCD"
  while [ $timeleft -gt 0 ] ; do
    plymouth display-message --text="you have $timeleft seconds to press A,B,C, or D..."
  plymouth display-message --text="Timed out..."
end script
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.