每天在特定时间执行shell脚本

时间:2016-01-12 21:08:28

标签: linux shell cron debian sh

我有一个简单的shell脚本,它只检查目录的内容,如果在白天添加了任何内容,则会将其复制到备份文件夹中。 我想在每天结束时执行这个脚本(让我们假设在23:55)。

此脚本驻留在其上的系统(Debian)始终打开(服务器类型)

我该怎么做?

5 个答案:

答案 0 :(得分:17)

要添加crontab作业,请在UNIX / Linux shell提示符下键入以下命令:

$ sudo crontab -e

添加以下行:

1 2 3 4 5 /path/to/script

,其中

1: Minutes (0-59)
2: Hours (0-23)
3: Days (1-31)
4: Month (1-12)
5: Day of the week(1-7)
/path/to/script - your own shell script

在你的情况下,它将是:

55 23 * * * /path/to/yourShellScript

答案 1 :(得分:12)

您想使用

编辑crontab文件
crontab -e

然后你要添加

55 23 * * * COMMAND TO BE EXECUTED

了解更多信息,请查看this

答案 2 :(得分:3)

我什么都不是,但是Linux专家,但谷歌的快速搜索让人想起了这个:

watch -n <your time> <your command/script>

这应该可以解决问题。有关详细信息,请查看以下内容:http://www.linfo.org/watch.html

答案 3 :(得分:2)

sudo crontab -e

55 23 * * * some_shell_script.sh

答案 4 :(得分:2)

查看Debian内置的Cron任务调度程序。只需将脚本条目添加到crontab文件中(请参阅:https://help.ubuntu.com/community/CronHowto)。

相关问题