Cannot get cron to work on Amazon EC2?

后端 未结 7 1523
南旧
南旧 2020-12-09 09:49

I\'ve spent two days trying to understand why I can not get cron to work on my Ubuntu EC2 instance. I\'ve read the documentation. Can anyone help? All I want is to get a wor

相关标签:
7条回答
  • 2020-12-09 09:51

    In my case the cron job was working but the script failed it was running failed. The failure reason was due to the fact that I used relative path instead of absolute path in my include line inside the script.

    0 讨论(0)
  • 2020-12-09 09:55

    Don't forget to specify the user to run it as. Try creating a new file inside your /etc/cron.d folder named after what you want to do like getnytimes and have the contents of that file just be:

    02 * * * * root /usr/bin/wget -O /home/ubuntu/backups/testfile http://www.nytimes.com/

    0 讨论(0)
  • 2020-12-09 10:02

    Your cron daemon is not running. When you're running ps aux | grep crond the result is showing that only the grep command is running. Be aware of this whenever you run ps aux | grep blah.

    Check the status of the cron service by running this command.

    Try:

    sudo service crond status
    

    Additional information here: http://www.cyberciti.biz/faq/howto-linux-unix-start-restart-cron/.

    0 讨论(0)
  • 2020-12-09 10:07

    Cron can be run in Amazon-based linux server just like in any other linux server.

    1. Login to console with SSH.
    2. Run crontab -e on the command line.
    3. You are now inside a vi editor of the crontab of the current user (which is by default the console user, with root permissions)
    4. To test cron, add the following line: * * * * * /usr/bin/uptime > /tmp/uptime
    5. Now save the file and exit vi (press Esc and enter :wq).
    6. After a minute or two, check that the uptime file was created in /tmp (cat /tmp/uptime).
    7. Compare it with the current system uptime by typing the uptime command on the command line.

    The scenario above worked successfully on a server with the Amazon Linux O/S installed, but it should work on other linux boxes as well. This modifies the crontab of the current user, without touching the system's crontabs and doesn't require the user inside the crontab entry, since you are running things under your own user. Easier, and safer!

    0 讨论(0)
  • 2020-12-09 10:09

    running

    /usr/bin/wget -O /home/ubuntu/backups/testfile http://www.nytimes.com/
    

    gives me an error

    /home/ubuntu/backups/testfile: No such file or directory
    

    is this your issue? I guess cron is not writing this error to anywhere you can redirect stderr to stdout and see the error like this :

    02 * * * * /usr/bin/wget -O /home/ubuntu/backups/testfile http://www.nytimes.com/ > /home/ubuntu/error.log 2&>1 
    
    0 讨论(0)
  • 2020-12-09 10:15

    One of the possible reasons for cronjob not running: Ensure that the server time and your cronjob time are same. I wasted a lot of time because of this.

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