0

So I'm aware that this is a somewhat convoluted usecase with probably not many practical applications, so unfortunately I wasn't able to find many helpful pointers so far.

Basically, I would like to have a terminal-only session that automatically runs a CLI application after login, and keeps restarting this application after a set amount of time (e.g. 1 minute) whenever it exits. For the duration where the application is exited, the shell should be regularly usable.

So here's my current setup (which works nicely so far):

  • I have a terminal-only session (no GUI, linux mint in this case).
  • After logging in, I automatically run an interactive CLI application (easy to do by adding it to .bashrc for example)
  • After the user exits my CLI application, they are back in their regular bash terminal and able to run commands (as they should)

Now the tricky part which I was unable to figure out so far:

  • How can I automatically restart the application in the user's terminal after a short time, while still keeping the terminal usable before that timeout is reached?
  • We can assume that the user won't be doing anything in the bash that could break things (such as starting additional shells, exiting running processes or logging out). They have to be able to run 1-2 other commands that complete quickly, but not much else.

I tried accomplishing this by running a script that (in a loop) alternates between running the application and running the timeout command that should start a new bash, but was unable to get it right. It doesn't seem to be possible to start an interactive bash session using the timeout command. So this might be one possible way to do it (pointers on the correct syntax are welcome), but any other approach or idea is also perfectly fine.

7
  • Your use case may be convoluted because you're using the wrong tool for the job. 2 Questions come to mind: 1) What are you trying to accomplish? and 2) If scripting is the right tool, why do you need to restart it over and over?
    – eyoung100
    Commented Apr 25 at 17:20
  • "I tried accomplishing this by running a script". How can we help you fix your problem with a script when you didn't include it in the body of your question? (-;? ... Use the {} tool from the Edit menu on the mouse-selected text aof your script so you get code/data/output/errMsg formatting. Good luck.
    – shellter
    Commented Apr 25 at 18:14
  • @shellter My approaches were so very futile that it felt rather pointless to try and include them. I figured there might be a simple solution by using a different approach to my problem. I'll take another look into it later and might be able to expand the question a bit.
    – RobinFood
    Commented Apr 26 at 17:52
  • @eyoung100 For some context: The usecase is actually part of a small puzzle/escape room experience I'm planning for someone. Among other things, they'll have an interactive application where they have to do certain things, and at some point they'll get information about how to "break out" of the CLI application (and later the room by running another command in the shell). I wanted the application to restart automatically for both thematic reasons (and in case they need to get back into it to obtain some more information).
    – RobinFood
    Commented Apr 26 at 17:56
  • I understand your point of view, it can be frustrating. But if you include your "best" version (or 2 or 3 "best" if they are small), then readers have a better idea of what your current understanding is, where the gaps in understanding are, and how they may be able to help you fix your issue. Here on S.O. almost any code is better than no code. Good luck.
    – shellter
    Commented Apr 26 at 17:56

1 Answer 1

1

I'm having the same thoughts here as Shelter Consider this pseudo-logic

answersRoomOneArray = {puzzleOneAnswer, puzzleTwoAnswer ... puzzleNAnswer}
# Room 1 Puzzles

puzzleOne () 
# Function to return a value
return puzzleOneAnswer

# Continue puzzles until Array is Full
...
if arrayCorrectRoomOne {} = answersRoomOne{} then
    unlockDoor ()
else
   punish ()
fi

You use the above format in each room terminal with a arrayCorrect stored somewhere in a directory the participants can't get to, in case they're terminal smart. Using this modular approach keeps you from needing a "controller script" without the need for a timer. If the script needs to restart clear the screen and restart it in the punish() function. If you only want so many attempts before they "die" add a counter to count how many times punish() was reached, and "kill" participants after X attempts.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .