Monday, December 4, 2023
rated 0 times [  14] [ 0]  / answers: 1 / hits: 13862  / 2 Years ago, sun, june 5, 2022, 1:59:59

I am looking for a method built-in to ubuntu that will allow me to run a script or program or whatever for a fixed period of time.

I found a program that does this in a way I like, but the package is unavailable for Ubuntu. In any case, I was hoping for something built-in.

The only thing i can think of is to get the current time and set a cron job 30 minutes from 'now' that will kill the program. I was hoping there was a way to do this without setting up a script, but if I need to - it wont be the end of the world. After the 30 minute interval I would like to put my laptop in a sleep mode, but this can be separate from the timer thing.

Thanks in advance.

More From » command-line


I've just wrote the following and it seems to work:

ping PID=$!; sleep 3; kill $PID

Of course you should substitute ping with the command you want to run and 3 with a timeout in seconds. Let me know if you need a more detailed explanation on how it works.

[#44955] Sunday, June 5, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 439
Total Questions: 99
Total Answers: 131

Location: Vanuatu
Member since Wed, Oct 14, 2020
3 Years ago
ettorina questions
Thu, Sep 1, 22, 15:28, 1 Year ago
Mon, Mar 14, 22, 06:04, 2 Years ago
Sun, Jul 24, 22, 13:31, 1 Year ago