Hot answers tagged

22

You are searching for at (at@wikipedia)? usr@srv % at now + 15 min at> YOUR COMMAND HERE You can define multiple commands that should be executed in 15 min, seperate them with a return. Confirm all commands with control+d.


15

How about: ( # In a subshell, for isolation, protecting $! while true; do perform-command & # in the background sleep 10 ; ### If you want to wait for a perform-command ### that happens to run for more than ten seconds, ### uncomment the following line: # wait $! ; ### If you prefer to kill a perform-command ### that ...


14

Use cron (or anacron). Cron is designed for running things at intervals. That is the only thing it does, and there has been a lot of work put into cron for many years to make it what it is today. The chances that you're going to write a better scheduler in your script are effectively nil. Using cron will work better, avoid having unnecessary code in your ...


13

#!/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 > bproduct.txt sleep 10 done Should work


12

Sleep can fail if it is terminated during execution: $ sleep 2 $ echo "$?" 0 $ sleep 2 ^C $ echo "$?" 130 Since sleep is an external executable, it is also conceivable that the fork or exec calls could fail, which would also cause bash to generate an error code >0.


11

I have had luck using PowerNap (it is packaged for ubuntu-sever, but the source is there so you should be able to compile it on anything) to suspend backup machines when they aren't doing anything. However, this won't wake them up automatically. There is also a PowerWake program bundled with the PowerNap source tarball (packaged as powerwake in Ubuntu) ...


11

terdon's suggestion would work but I guess mine is more efficient. difference=$(($(date -d "4:00" +%s) - $(date +%s))) if [ $difference -lt 0 ] then sleep $((86400 + difference)) else sleep $difference fi This is calculating the difference between the given time and the current time in seconds. If the number is negative we have to add the seconds ...


7

In newer versions of bash (at least v2), builtins may be loaded (via enable -f filename commandname) at runtime. A number of such loadable builtins is also distributed with the bash sources, and sleep is among them. Availability may differ from OS to OS (and even machine to machine), of course. For example, on openSUSE, these builtins are distributed via the ...


7

sleep on Linux accepts seconds too (at least all the versions I've ever seen); can't you just use sleep 600 on both?


7

Use cron because it is a better and more standard practice. At least if this is something that will regularly run (not just something you patched together in a minute). cron is a cleaner and more standard way. It's also better because it runs the shell detached from a terminal - no problem with accidental termination and dependencies on other processes. ...


7

sleep.target is specific to system services. The reason is, sleep.target is not a magic target that automatically gets activated when going to sleep. It's just a regular target that puts the system to sleep – so the 'user' instances of course won't have an equivalent. (And unfortunately the 'user' instances currently have no way to depend on systemwide ...


7

if the user is allowed to use at command, this is the perfect use for that: $ at 08:00 022116 at> myscript.sh at> <----------- ctrl-d here job 9 at 2016-02-21 08:00 if you get a message like "user blah is not able to run at", ask the syadmin to add this user to at.allow file or remove from at.deny file, depending on how it is used in your ...


6

The fade out is probably the screensaver kicking in. Try to disable it by going to System->Preferences->Look and Feel->Screensaver and disabling "Activate screensaver when computer is idle" if indeed the active screen saver is "Blank screen". The fact that the fading out can't be interrupted is a bug it seems. E.g. Fedora has a bugreport stating it is a ...


6

OS X can do this now, as of Snow Leopard. It's made possible through the Sleep Proxy Service. It's pretty much automatic. The only requirement is that you have a second always-on Apple device on your LAN that can act as the sleep proxy. Their current low-power embedded boxes all support this, I believe: Airport, Time Machine, and Apple TV. In the ...


6

See time(7), and the manpages it references. An excerpt: High-Resolution Timers Before Linux 2.6.21, the accuracy of timer and sleep system calls (see below) was also limited by the size of the jiffy. Since Linux 2.6.21, Linux supports high-resolution timers (HRTs), optionally configurable via CONFIG_HIGH_RES_TIMERS. On a system that ...


6

Assuming it is a shell script, this should work: while [ $(date +%H:%M) != "04:00" ]; do sleep 1; done That's for 24 hour times. If you want this to continue both at 4:00 AM and 4:00 PM, use this instead: while [ $(date +%I:%M) != "04:00" ]; do sleep 1; done


5

Creating a lot of subprocesses is a bad thing in an inner loop. Creating one sleep process per second is peanuts. There's nothing wrong with while ! test_condition; do sleep 1 done If you really want to avoid the external process, you don't need to keep the fifo open. my_tmpdir=$(mktemp -d) trap 'rm -rf "$my_tmpdir"' 0 mkfifo "$my_tmpdir/f" while ! ...


5

The definition of sleep(3) allows for the call to return before, at, or after the time specified: DESCRIPTION sleep() makes the calling thread sleep until seconds seconds have elapsed or a signal arrives which is not ignored. So we have these possible scenarios The call is interrupted with an uncaught signal. sleep() returns immediately and ...


4

Unless you're running a realtime kernel, I wouldn't use sleep times < 10ms anyway tbh. Even if the scheduler is willing to pre-empt another process for your timeout, jitter will probably dominate your actual sleep times. Summary: avoid such small intervals unless you have a realtime kernel. If you can't change kernel, your best bet may be to pin your ...


4

As root user, and since Fedora 20 uses systemd the more appropiated way to do this is through the hibernate target: systemctl hibernate If you want to do this as normal user, you could use sudo and add the following line on /etc/sudoers through the visudo command: user hostname =NOPASSWD: /usr/bin/systemctl hibernate Other solution to allow hibernate ...


3

You should assume that any command can fail for various reasons even if having sleep fail is indeed very unlikely. ( sleep 10 ; echo "hello world" ) & means background sleep and execute echo after sleeping process but if sleep fails echo will run anyway see complete explanation sleep 10 && echo "hello world" & means you need to wait ...


3

Also can check RF kill switches, try "rfkill list all", and if thats interesting persue further.


3

It would be easier to simply launch the program directly and have it run the update immediately (or it could sleep for some small delay if you really needed it to). If this is in a script itself (eg, bash), simply call the update script directly (likely redirecting the output): update-my-thingy < /dev/null > /dev/null 2>&1 If it's in a ...


3

I use a short script I keep in my path, called after, containing at now + "$@" This way it's very easy to, for example, type: after 15 min then any commands and Ctrl-D, or echo COMMANDS | after 15 min which does the same.


3

Check your paths! A common mistake when creating cron jobs is assuming that the path is the same when the cron runs as when the user runs the file. mysqldump, and expect might need to be given full paths, instead of relative ones.


3

a; b always runs the second command after the first, whereas a && b runs the second command only if the first is successful, i.e. only if the first command returns the status 0. sleep always returns the status 0, except when it's killed by a signal, in which case the status is 128 + signal number. (The status can also be 126 or 127 if the sleep ...


3

There are already some good answers on cron and sleep performance, but I want to add some kind of feature comparison. Pro cron: running already on Unix/Linux systems stable and proven designed for background processes runs from system start-up onward, and so will your script, once installed easier entry of long-term cycles (hours, days, weeks) allows ...


3

man bash says: The shell learns immediately whenever a job changes state. Normally, bash waits until it is about to print a prompt before reporting changes in a job's status so as to not interrupt any other output. If the -b option to the set builtin command is enabled, bash reports such changes immediately. Any trap on SIGCHLD is ...



Only top voted, non community-wiki answers of a minimum length are eligible