有没有办法在crontab文件中模拟bash shell?
我注意到当我尝试在命令中使用bash的’date’时,我不能,当我试图获取一个因日期而异的文件时。
问题是cron
将%
视为换行符。 来自man 5 crontab
:
Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.
要解决这个问题,你需要通过\%
来逃避\%
。
或者,如果您想从bash
脚本运行该命令,请使脚本可执行并将其放置在如下所示的crontab -e
:
05 06 * * * /path/to/script.sh
使脚本的shebang为:
#!/usr/bin/env bash
现在bash
脚本将每天早上6:05运行。