openwrt /etc/config/crontabs可以写入多个任务吗
时间: 2023-07-30 14:06:30 浏览: 43
是的,OpenWrt 的 `/etc/config/crontabs` 文件可以写入多个任务。您可以在该文件中添加多个任务,每个任务占用一行,并按照特定的格式指定任务的执行时间和要执行的命令。
以下是一个示例 `/etc/config/crontabs` 文件,其中包含了两个任务:
```
# Example crontab file
# Edit this file to introduce tasks to be run by cron.
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# +---------------- minute (0 - 59)
# | +------------- hour (0 - 23)
# | | +---------- day of month (1 - 31)
# | | | +------- month (1 - 12)
# | | | | +---- day of week (0 - 6) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed
# Run a script every hour
0 * * * * /path/to/script.sh
# Update package list every day
0 0 * * * /usr/bin/opkg update
```
在这个示例中,第一个任务是每小时执行一次 `/path/to/script.sh` 脚本,第二个任务是每天凌晨执行 `/usr/bin/opkg update` 命令更新软件包列表。每个任务占用一行,并按照特定的格式指定任务的执行时间和要执行的命令。每个字段的含义可以参考注释中的解释。
需要注意的是,如果要添加或修改 `/etc/config/crontabs` 文件中的任务,在修改后需要重启 cron 服务才能生效。可以使用以下命令重启 cron 服务:
```
/etc/init.d/cron restart
```
或者使用以下命令启动 cron 服务:
```
/etc/init.d/cron start
```