I want to pause a certain bash script for 30 minutes. Right now I use sleep 1800 but that doesn't take into account time the laptop might be in suspend (sleep) state. Is there way to achieve this?

If, right now, it is 12:53 pm, I want to resume the program at 1:23 am. But in meantime, the computer can be in sleep state. If the computer sleeps until later than 1:23 am, then I want the program to resume immediately after resuming from sleep.


1 Answer 1


Maybe wrap it in a while loop and test if your at the scheduled time.


SOON=$(($(date +%s) + 1800))                                   
while [[ "$NOW" -le "$SOON" ]]; do                         
    sleep 1                            
    NOW=$(date +%s)                                     

The date idea can also be found in this answer by chepner. The +%s makes date format the date in seconds since 1970 something. $(( )) just arithmetically adds the amount of seconds. Replace 1800 with any amount (probably best to test with a low amount and see if it works). sleep 1 makes the script check the condition every second.

You must log in to answer this question.

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