Sometimes you will need to delay for a specified time, pause for an amount of time specified by the sum of the values of the command line arguments. To get this done we can use sleep. The syntax is:
s - seconds (default)
m - minutes
h - hours
d - days
NOTE: We we do not use any suffix then it automatically takes seconds as suffix.
Uses of sleep command:
Just imagine you have a script which copies files from any other server and they cannot be copied until they are downloaded fully. To achieve this you have to run a download process separately in different script. Now the scenario is that the copy script will continuously testing for the files whether they are downloaded or not results in high CPU usage.
Instead of this you can use sleep command and tests every 1 minutes whether all files are downlaoded or not then copies the file. It will not keep busy your CPU and results in good performence.
Examples:
To sleep for 10 seconds, use:
here, suffix are
s - seconds (default)
m - minutes
h - hours
d - days
NOTE: We we do not use any suffix then it automatically takes seconds as suffix.
Uses of sleep command:
Just imagine you have a script which copies files from any other server and they cannot be copied until they are downloaded fully. To achieve this you have to run a download process separately in different script. Now the scenario is that the copy script will continuously testing for the files whether they are downloaded or not results in high CPU usage.
Instead of this you can use sleep command and tests every 1 minutes whether all files are downlaoded or not then copies the file. It will not keep busy your CPU and results in good performence.
Examples:
To sleep for 10 seconds, use:
To sleep for 3 minutes, use:
To sleep for 6 hours, use:
To sleep for 4 days, use:
To sleep for .2 seconds:
To run commmand1, sleep for half minute and finally run command2:
To sleep in bash for loop:
To run while loop to display date and hostname on screen:
To check version of sleep:
It will shows the current version of sleep installed on the server.