Run a Terminal Command after n Seconds Has Passed

It is sometimes desirable to run a command after n seconds has passed e.g. to run a command after the approximate time taken for deploy pipeline to complete.

Scheduling the command for a couple of minutes’ time allows me to progress to other tasks – thus clearing it off my list – or walk away from my desk, and not need to worry about running the script manually.

The Sleep Command

This command will pause for NUMBER seconds.

Syntax: sleep <number of seconds>.

To use the sleep command before running a script, use as follows:

sleep <seconds> && <your script>

Example: To run php my-script.php after 10 seconds of waiting, the following command would be used:

sleep 10 && php my-script.php

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *