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

My 3-year girl loves SuperTux. She can't control the mouse, so the game should run automatically on startup. After the game, the computer should shut down automatically.

However when I put the below command in "crontab -e":

@reboot env DISPLAY=:0.0 /usr/games/supertux2 && echo "PASSWORD" | sudo -S shutdown -h now

The first part runs the game on an old PC at boot time. I expected the second part of the command to turn off the computer when my girl exits the game but it isn't working.

Doesn't the chain-command A && B mean when the A finished, start B?

How can I automate the powering off computer when the game is closed?

share|improve this question

Technically, A && B will only execute B when A is successful (exits with status of EXIT_SUCCESS, i.e. 0). Likewise, A || B will only execute B when A fails. Another option could be A; B which should execute B regardless of the exit status of A, but not until A has completed. I don't know how the games is currently exiting, but if it is not exiting with an EXIT_SUCCESS status, then B won't get executed.

To test this you can run the following commands and see which ones generate the string:

perl -e 'exit 0' && echo "exit was successful"
perl -e 'exit 0' || echo "exit was successful"
perl -e 'exit 0'; echo "exit was successful"
perl -e 'exit 1' && echo "exit was failure"
perl -e 'exit 1' || echo "exit was failure"
perl -e 'exit 1'; echo "exit was failure"

Finally, you could create a shell script /usr/games/

echo "PASSWORD" | sudo -S shutdown -h now

And then call that on reboot, rather than /usr/games/supertux2

share|improve this answer
";" solved _____ Thanks for the info. "||" also was new to me :) But your proposal script runs supertux2 and then goes to the second line which is "turning off the computer" Am I right? "Enter" = ";"? – mini May 3 '13 at 20:35
I believe that "Enter" and ";" should do the same thing. I'm not sure why it went directly to the second line, but I'm glad that the ";" solved it. – Dr.Tower May 3 '13 at 21:27
Dr. Tower script is the proper way to do it. Scripts are executed line by line, thus once first line quits, it Will go to second. Upvote given – Serg Feb 24 at 21:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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