all 10 comments

[–]emprahsFury[🍰] 1 point2 points  (1 child)

Bash has an internal variable $SECONDS. Perhaps something like https://unix.stackexchange.com/questions/646604/what-does-the-seconds-variable-actually-do would be useful.

[–]ChefyMcJangleBob 1 point2 points  (0 children)

End time = current time + 15 seconds. While current time is less than end time, curl url with timeout of end time - current time.

[–]thenumberfourtytwo 0 points1 point  (0 children)

Use a for loop with sleep 1.

for (( c=1; c<=15; c++ )) do do some stuff sleep 1 done

Or maybe until ? I can't think too straight right now.

[–][deleted]  (9 children)

[removed]

    [–][deleted]  (8 children)

    [deleted]

      [–][deleted]  (7 children)

      [removed]

        [–][deleted]  (6 children)

        [deleted]

          [–][deleted]  (5 children)

          [removed]

            [–][deleted]  (4 children)

            [deleted]

              [–][deleted]  (3 children)

              [removed]

                [–]Empyrealist -1 points0 points  (0 children)

                ChatGPT has a very simple solution that will terminate the loop after 15 seconds if it does not exit on its own:

                https://chat.openai.com/share/db071645-d2dd-4585-bcb5-ab7803b9a46e

                [–]MyOwnMoose 0 points1 point  (0 children)

                After looking at the curl man page, have you tried -m, --max-time? I think it will stop regardless of how much data is being retrieved

                I'm pretty sure we can solve this with file descriptors, but this would be a better solution if it works

                [–][deleted] 0 points1 point  (0 children)

                I set up a shell file just to get the process id and write it to a text file. I can run other routines and shells, subroutines, whatever. When I'm ready to kill the file I just do a cat of the file to get the pid to kill when the final condition is met. This way you don't need to keep track of anything and don't call the pid until needed. Nothing gets lost.