Windows中在Ubuntu 16.04中未运行2个cronjob中的1个-由于cron中的`date`扩展

时间:2019-02-02 00:10:35

标签: bash cron windows-subsystem-for-linux

我的crontab中有两个cronjob。第一部作品;第二个没有。具体来说,

40 18 * * * cp /mnt/c/Users/Adrian/pick_of_the_day/daily_winner /mnt/c/Users/Adrian/pick_of_the_day/`date +'%b-%d-winner'` 

不起作用。

我尝试过:

- commenting out the first one
- removing the full path for the destination file and checking the default DIR for my user
- using a relative path for the dest file
- looking through 5 other cronjob questions on this site
- looking for the cron log file but it doesn't exist.  Before someone tells me to check syslog, please note it doesn't exist on my installation.
- **I removed the ">>/var/log/cron_output.log 2>&1" and just left the command**

Aviator@AW:/var/log$ ls alternatives.log btmp dpkg.log fsck lxd upstart apt dist-upgrade fontconfig.log lastlog unattended-upgrades wtmp Aviator@AW:/var/log$

35 18,21 * * * /mnt/c/Users/Adrian/pick_of_the_day/winner
40 18 * * * cp /mnt/c/Users/Adrian/pick_of_the_day/daily_winner 
/mnt/c/Users/Adrian/pick_of_the_day/`date +'%b-%d-winner'` >>/var/log/cron_output.log 2>&1

1 个答案:

答案 0 :(得分:1)

在cron需要%将字符而它们如果在脚本或直接在CMD线不逃脱。

逸出他们的cronjob然如预期之后。

cp /mnt/c/Users/Adrian/pick_of_the_day/daily_winner /mnt/c/Users/Adrian/pick_of_the_day/$(date +'\%b\%mwinner')

我刚刚找到的相关答案: https://unix.stackexchange.com/questions/29578/how-can-i-execute-date-inside-of-a-cron-tab-job

https://unix.stackexchange.com/questions/252615/why-doesnt-date-f-t-work-in-crontab