【问题标题】:crontab not working in AWS EC2 instancecrontab 在 AWS EC2 实例中不起作用
【发布时间】:2018-01-11 00:46:45
【问题描述】:

我正在努力让我的 AWS EC2 实例 (Amazon Linux AMI) 中的 crontabs 运行我的 R 脚本,所以我写了一个非常基本的 cronjob 只是为了测试 crontabs 是否在我的实例中工作:

crontab -e

* * * * * echo "Is this working" 
* * * * * echo "write to script" >> testfile.txt

save the crontab

然而,这些都没有做任何事情(运行作业的终端没有输出/我的主目录中没有写入新的文本文件)...

如何让 crontabs 在我的 AWS EC2 实例中工作?

编辑:我尝试在命令行中运行以下命令,但没有成功...

sudo service cron start
cron: unrecognized service

EDIT2:我也得到以下内容

ps aux | grep crond
root      2694  0.0  0.0 121604  2580 ?        Ss   Jan10   0:00 crond
root      5491  0.0  0.0 110472  2044 pts/0    S+   00:52   0:00 grep --color=auto crond

【问题讨论】:

    标签: amazon-ec2 cron


    【解决方案1】:

    您可以为 cron 设置环境变量。

    您是否尝试检查以下环境变量?

    • 首页
      • 表示 cron 用户的主目录。我猜它被定义为“/”
    • 路径
      • 它定义了 cron 用户的 $PATH。也请这个变量。

    你可以看到来自/etc/crontab的示例crontab

    $ cat /etc/crontab
    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    MAILTO=root
    HOME=/
    
    # For details see man 4 crontabs
    
    # Example of job definition:
    # .---------------- minute (0 - 59)
    # |  .------------- hour (0 - 23)
    # |  |  .---------- day of month (1 - 31)
    # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
    # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
    # |  |  |  |  |
    # *  *  *  *  * user-name command to be executed
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-11
      • 2019-09-11
      • 2014-05-22
      • 2015-03-18
      • 1970-01-01
      • 2020-11-18
      • 2014-01-31
      相关资源
      最近更新 更多