Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

My 3-year girl loves SuperTux. she couldn't control the mouse! so the game should run automatically on startup and after the game, computer should shut down automatically, too.

however 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 can turn off the computer when my girl exit the game. but it can't.

does not the chain-command A && B mean when the A finished, start the B?

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

share|improve this question

1 Answer 1

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/supertux2.sh:

#!/bin/sh
/usr/games/supertux2
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

Your Answer

 
discard

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.