【问题标题】:Cron jobs not working in Homestead无法在 Homestead 工作的 Cron 工作
【发布时间】:2016-03-08 14:16:16
【问题描述】:

我在我的 win8 笔记本电脑上运行 Homestead,而我的 Cron 似乎根本没有运行。我正在尝试让预定的作业为 Laravel 工作,但目前我一直坚持让 Cron 运行。

这是我的 crontab,只是一些简单的尝试调试它。

vagrant@homestead:~$ crontab -l
* * * * * date >> /home/vagrant/Code/CRONTRACK.txt
* * * * * /usr/bin/php artisan schedule:run >> /home/vagrant/Code/laravel_cron_output.txt

当使用 crontab -e 尝试编辑我的 crontab 时,这看起来正确吗?

vagrant@homestead:~$ crontab -e
143

现在当我尝试检查我的系统以查看 cron 是否运行任何东西时

vagrant@homestead:~$ grep CRON /var/log/syslog
Dec  3 19:41:01 homestead CRON[3628]: (vagrant) CMD (date >> /home/vagrant/Code/CRONTRACK.txt^M)
Dec  3 19:41:01 homestead CRON[3629]: (vagrant) CMD (/usr/bin/php artisan schedule:run >> /home/vagrant/Code/laravel_cron_output.txt^M)
Dec  3 19:41:01 homestead CRON[3627]: (vagrant) MAIL (mailed 1 byte of output; but got status 0x004b, #012)
Dec  3 19:41:01 homestead CRON[3626]: (vagrant) MAIL (mailed 1 byte of output; but got status 0x004b, #012)
Dec  3 19:42:01 homestead CRON[3635]: (vagrant) CMD (date >> /home/vagrant/Code/CRONTRACK.txt^M)
Dec  3 19:42:01 homestead CRON[3636]: (vagrant) CMD (/usr/bin/php artisan schedule:run >> /home/vagrant/Code/laravel_cron_output.txt^M)
Dec  3 19:42:01 homestead CRON[3634]: (vagrant) MAIL (mailed 1 byte of output; but got status 0x004b, #012)
Dec  3 19:42:01 homestead CRON[3633]: (vagrant) MAIL (mailed 1 byte of output; but got status 0x004b, #012)
Dec  3 19:43:01 homestead CRON[3642]: (vagrant) CMD (date >> /home/vagrant/Code/CRONTRACK.txt^M)
Dec  3 19:43:01 homestead CRON[3643]: (vagrant) CMD (/usr/bin/php artisan schedule:run >> /home/vagrant/Code/laravel_cron_output.txt^M)
Dec  3 19:43:01 homestead CRON[3641]: (vagrant) MAIL (mailed 1 byte of output; but got status 0x004b, #012)
Dec  3 19:43:01 homestead CRON[3640]: (vagrant) MAIL (mailed 1 byte of output; but got status 0x004b, #012)
Dec  3 19:44:01 homestead CRON[3649]: (vagrant) CMD (date >> /home/vagrant/Code/CRONTRACK.txt^M)
Dec  3 19:44:01 homestead CRON[3650]: (vagrant) CMD (/usr/bin/php artisan schedule:run >> /home/vagrant/Code/laravel_cron_output.txt^M)
Dec  3 19:44:01 homestead CRON[3648]: (vagrant) MAIL (mailed 1 byte of output; but got status 0x004b, #012)
Dec  3 19:44:01 homestead CRON[3647]: (vagrant) MAIL (mailed 1 byte of output; but got status 0x004b, #012)
Dec  3 19:45:01 homestead CRON[3656]: (vagrant) CMD (date >> /home/vagrant/Code/CRONTRACK.txt^M)
Dec  3 19:45:01 homestead CRON[3657]: (vagrant) CMD (/usr/bin/php artisan schedule:run >> /home/vagrant/Code/laravel_cron_output.txt^M)
Dec  3 19:45:01 homestead CRON[3655]: (vagrant) MAIL (mailed 1 byte of output; but got status 0x004b, #012)
Dec  3 19:45:01 homestead CRON[3654]: (vagrant) MAIL (mailed 1 byte of output; but got status 0x004b, #012)

似乎它有效,但我找不到我通过管道输出的 txt 文件!

vagrant@homestead:~$ cat /home/vagrant/Code/CRONTRACK.txt^M
cat: /home/vagrant/Code/CRONTRACK.txt^M: No such file or directory
vagrant@homestead:~$ cat /home/vagrant/Code/CRONTRACK.txt
cat: /home/vagrant/Code/CRONTRACK.txt: No such file or directory
vagrant@homestead:~$ ll /home/vagrant/Code/
total 82
drwxrwxrwx 1 vagrant vagrant  4096 Dec  3 18:59 ./
drwxr-xr-x 7 vagrant vagrant  4096 Dec  3 19:31 ../
-rwxrwxrwx 1 vagrant vagrant   153 Dec  3 19:24 crontab.txt*
-rwxrwxrwx 1 vagrant vagrant 70449 Oct 15 20:44 memcached-2.2.0.tgz*
drwxrwxrwx 1 vagrant vagrant  4096 Oct 20 19:05 sample/
vagrant@homestead:~$

直接在终端中运行我给 Cron 的命令效果很好!

vagrant@homestead:~$ date >> /home/vagrant/Code/CRONTRACK.txt^M
vagrant@homestead:~$ cat /home/vagrant/Code/CRONTRACK.txt^M
Thu Dec  3 19:53:06 UTC 2015  

另外,^M 是从哪里来的?它没有出现在 crontab -l 中。

【问题讨论】:

    标签: linux laravel ubuntu cron homestead


    【解决方案1】:

    问题已解决。 我在记事本中制作了我的 crontab 文件,它在我的新行中附加了 linux 不喜欢的回车符。

    crontab -l
    

    不显示 CR(我不明白为什么不显示它对于 linux 的这样一个问题!?!?)。

    所以需要使用 notepad++ 和 sublime text 来查找和解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-13
      • 1970-01-01
      • 2012-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多