Ubuntu: How can I open a file if it crashes while I'm away?


Hello I've looked up how to re-start a file if it crashes/closes automatically, but I have no experience in scripting and linux in general. I've just started a game-server and sometimes it closes because it has some errors in-game and people report them to me, so while I fix those errors, I would love to know how to restart it without being physically in my computer.

If I'm not wrong this can be done with a .bat file. Or does that only works in windows?


If you want a command YOUR_COMMAND to always be restarted when it exits, simply put it in a loop, like

while true; do YOUR_COMMAND ; sleep 5 ; done  

Note that I added a 5 seconds delay between the command's end and its restart. You can abort the loop by pressing Ctrl+C in the terminal where it runs.

If you want the loop to only restart your COMMAND if it terminated with an exit code other than 0 (which should indicate an error/non-successful run), as @KonradRudolph suggested, you can do it like this:

while ! YOUR_COMMAND ; do sleep 5 ; done  

Note that YOUR_COMMAND must exit with status 0 to end the loop or with status != 0 to get restarted when you use this structure.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »