a command for delaying execution of a program for the given length of time. For low power mode, use *suspend* instead.
Questions tagged [sleep]
187 questions
83
votes
3 answers
How do I start a Cron job 1 min after @reboot?
I need my script to be executed a minute after each reboot. When I apply @reboot in my crontab it is too early for my script - I want the script to be executed after all other tasks that are routinely run on reboot. How might I run the script…
Yurij73
- 1,922
- 6
- 20
- 32
35
votes
6 answers
Running a loop precisely once per second
I'm running this loop to check and print some things every second. However, because the calculations take maybe a few hundred milliseconds, the printed time sometimes skip a second.
Is there any way to write such a loop that I am guaranteed to get a…
forthrin
- 2,209
- 2
- 27
- 46
33
votes
8 answers
cron Vs. sleep - which is the better one in terms of efficient cpu/memory utilization?
The Case:
I need to run some commands/script at certain intervals of time and for this I have two options:
set up a cron-job
implement a loop with sleep in the script itself.
Question:
Which is the better option from resource consumption point of…
rusty
- 1,841
- 6
- 21
- 25
28
votes
10 answers
Shell: is it possible to delay a command without using `sleep`?
Are there any substitutes, alternatives or bash tricks for delaying commands without using sleep? For example, performing the below command without actually using sleep:
$ sleep 10 && echo "This is a test"
user321697
- 309
- 1
- 3
- 4
27
votes
8 answers
Avoiding busy waiting in bash, without the sleep command
I know I can wait on a condition to become true in bash by doing:
while true; do
test_condition && break
sleep 1
done
But it creates 1 sub-process at each iteration (sleep). I could avoid them by doing:
while true; do
test_condition &&…
jfg956
- 5,988
- 3
- 22
- 24
23
votes
2 answers
How to run systemd user service to trigger on sleep (aka. suspend, hibernate)?
Based on various sources I have cobbled together ~/.config/systemd/user/screenlock.service:
[Unit]
Description=Lock X session
Before=sleep.target
[Service]
Environment=DISPLAY=:0
ExecStart=/usr/bin/xautolock…
l0b0
- 50,672
- 41
- 197
- 360
15
votes
2 answers
bash script: fixed sleep time is adding up in while loop
I am new to bash scripting and started out with a few sample scripts.
One is:
#!/bin/bash
SECONDS=5
i=1
while true
do
echo "`date`: Loop $i"
i=$(( $i+1 ))
sleep $SECONDS
done
This results in:
Sunday 10 May 15:08:20 AEST…
MaxG
- 403
- 1
- 5
- 12
13
votes
3 answers
Sleep until next occurrence of specific time
I need a series of commands or a single command that sleeps until the next occurrence of a specific time like "4:00" occurs.
How would I do that?
The at command or a cronjob is not a option because I must not leave the script I'm currently in.
The…
BrainStone
- 3,534
- 12
- 32
- 53
12
votes
6 answers
at some time from now do something (and maybe also show result in console)
I use Ubuntu server 16.04 and I desire to use the utility at in my current session to do something 1 minute from now (say, an echo), without giving a specific date and time - just 1 minute ahead from current time.
This failed:
echo 'hi' | at 1m
The…
Arcticooling
- 1
- 12
- 44
- 103
12
votes
3 answers
Perform command every X seconds
I wish to perform a command ever 10 seconds, and have it executed in the background (thereby eliminating watch?). All the answers show something like the following, but this will execute ever 11 to 14 seconds. How can this be accomplished?
while…
user1032531
- 1,877
- 6
- 29
- 35
12
votes
1 answer
Wake monitor from sleep remotely
I have an Ubuntu server running xdm with openbox on which is plugged a monitor that displays a video which is launched via a cron daemon.
When the monitor is not used for a certain amount of time, it goes into sleep mode and I cannot wake it up with…
Jav
- 960
- 3
- 11
- 23
11
votes
5 answers
How to determine the amount of time left in a "sleep"?
I have:
sleep 210m && for i in $(seq 1 5); do echo -e '\a'; sleep 0.5; done
running as a simple, no-frills timer to remind me when something should be done. That sleep 210m is PID 25347.
I'm trying to figure out how much time is left in the sleep.…
derobert
- 107,579
- 20
- 231
- 279
10
votes
2 answers
How to power off a system but still keep it available on the network
I'm looking into installing a file server on my network, for serving data and backups.
I want this machine to be available at all times, but I would rather not keep it on all the time (as to conserve power).
Is it possible to set things up so that…
Ruben Vermeersch
- 373
- 1
- 4
- 8
9
votes
1 answer
Adding Sleep command to shell script?
How can I add a 10sec sleep to my loop after each page is processed?
#!/bin/sh
for page in {1..50}
do
wget -q -U Mozilla "http://admin.domain.com/products_search/?p=$page" -O - \
| tr '"' '\n' | grep "^Product photo for " | cut -d ' ' -f 3…
acctman
- 195
- 1
- 1
- 4
9
votes
1 answer
Why does sleep, when run in a shell script, ignore SIGINT?
When I run sleep manually, and then kill -INT it, sleep exits immediately. For example:
$ /bin/sleep 60 &
[1] 4002356
$ kill -INT 4002356
[1]+ Interrupt /bin/sleep 60
$ ps -C sleep
PID TTY TIME CMD
$
However,…
mpb
- 1,501
- 1
- 15
- 23