Run two commands sequentially using crontab
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
Related videos on Youtube
mini
Updated on September 18, 2022Comments
-
mini over 1 year
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?
-
mini about 11 years";" 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" = ";"?
-
rjsnavarette about 11 yearsI 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.
-
Sergiy Kolodyazhnyy about 8 yearsDr. 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