Linux How to run script at certain time?

I have a text file containing a specific date and time. I want to be able to run a script at the time specified in that file. How would you achieve that? Create another script that runs in background (sort of a deamon) and checks every second if the current time is matching the time in the file? Is there another way? The machine is a linux server , Debian wheezy. Thanks in advance


Look at the following:

echo "ls -l" | at 07:00

This code line executes "ls -l" at a specific time. This is an example of executing something (a command in my example) at a specific time. "at" is the command you were really looking for. You can read the specifications here:

http://manpages.ubuntu.com/manpages/precise/en/man1/at.1posix.html http://manpages.ubuntu.com/manpages/xenial/man1/at.1posix.html

Hope it helps!


at命令专门用于此目的(与用于调度重复性任务的cron不同)。

at $(cat file) </path/to/script

Cron is good for something that will run periodically, like every Saturday at 4am. There's also anacron , which works around power shutdowns, sleeps, and whatnot. As well as at .

But for a one-off solution, that doesn't require root or anything, you can just use date to compute the seconds-since-epoch of the target time as well as the present time, then use expr to find the difference, and sleep that many seconds.

链接地址: http://www.djcxy.com/p/49492.html

上一篇: 我可以在VIM中做什么,但在Visual Studio中无法做到这一点?

下一篇: Linux如何在特定时间运行脚本?