Crontab is not working on Amazon EC2 server

前端 未结 5 590
渐次进展
渐次进展 2020-12-21 14:52

Crontab is not working on Amazon EC2 Linux Server.

I have saved below codes in /etc/crontab file

crontab
# For details see man 4 crontabs 
# Example          


        
相关标签:
5条回答
  • 2020-12-21 15:25

    You should use crontab -e to create cron for the logged user, so that you don't need to inform the username. See here: https://stackoverflow.com/a/16986464/1777152

    0 讨论(0)
  • 2020-12-21 15:36

    Solved the problem.

    I used this code and it works!

    * 2 * * * root tar cvfpz /home/backup/web_`date +\%Y\%m\%d`.tar.gz /home/web
    
    0 讨论(0)
  • 2020-12-21 15:38

    Don't use nano, use the native sudo crontab -e command.

    0 讨论(0)
  • 2020-12-21 15:39

    For people who are dealing with AWS machines and EBS you need to specify the root keyword before the command since ec2-user isn't allowed to run crontabs. Of course there's a way to fix that.

    you can edit the crontab by typing sudo nano /etc/cron.d/mycrontabs or crontab -e

    * * * * * root bla bla

    • Also make sure e that the file is ended with a new line
    0 讨论(0)
  • 2020-12-21 15:40

    I recently began using Amazon's linux distro on ec2 instances and after trying all kinds of things for cron all I needed was:
    sudo service crond start
    crontab -e
    This allowed me to set a cron job as "ec2-user" without specifying the user. For example:
    0 12 * * * python3 example.py
    In fact, specifying a user here prevented it from running.

    0 讨论(0)
提交回复
热议问题