无法在Amazon EC2上设置的cron作业 [英] Unable to setup cron-job on Amazon EC2

查看:190
本文介绍了无法在Amazon EC2上设置的cron作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Amazon EC2实例(Ubuntu服务器13.04 - 64位[AMI-bf1d8a8f])上运行自己的网站。我需要设置一个cron作业收到一封电子邮件警报日常生活。

I have an Amazon EC2 instance (Ubuntu Server 13.04 - 64 bit [ami-bf1d8a8f]) running my website. I need to setup a Cron Job to get an email alert everyday.

有没有人有任何意见或可能的解决方案?

Does anyone have any advise or possible solutions?

感谢您的时间。

推荐答案

这只是一样通过命令行设置一个cron作业,任何其他服务器上。

It's just the same as setting up a cron job on any other server via command line.

  1. 通过SSH连接
  2. 导航到 /etc/cron.daily
  3. 请运行一个新的脚本/调用PHP脚本发送邮件/其他任务
  4. 确保其执行
  1. Connect via SSH
  2. Navigate to /etc/cron.daily
  3. Make a new script that runs / calls a PHP script to send the email/other tasks
  4. Make sure its executable

您可以使用命令,如的wget -q -O TEMP.TXT http://www.site.com/cron.php 来调用PHP脚本,或通过命令行 PHP /var/www/site/cron.php

You can use a command such as wget -q -O temp.txt http://www.site.com/cron.php to call the PHP script, or via command line php /var/www/site/cron.php.

关于的wget 方法, TEMP.TXT 将包含脚本的输出,也可以重定向输出的/ dev / null的。这将只是放弃所有的输出。如果您需要保存的cron脚本的输出,你决定去与命令行方式,那么你可以将数据输出到文件 PHP /var/www/site/cron.php> output.txt的

Regarding the wget method, temp.txt will contain the output of the script, or you can redirect the output to /dev/null. This will just discard all output. If you need to save the output of the cron script and you decided to go with the command line method then you can output the data to a file php /var/www/site/cron.php > output.txt

如果你需要更多的解释/细节发表评论。也看看<一href="http://stackoverflow.com/questions/11779599/basic-cron-job-set-up-to-execute-php-file-daily">Basic cron作业设置为执行PHP文件在每天

If you need more explanation/detail post a comment. Also take a look at Basic cron job set up to execute php file daily

通过SSH连接到该实例,导航到 CD /etc/cron.daily日常的cron文件夹。接着键入 sudo的纳米mailscript ,公告不存在 .SH bash的扩展。我有一个问题,这引起了脚本不运行扩展。

Connect to the instance via SSH, navigate to the daily cron folder with cd /etc/cron.daily. Next type sudo nano mailscript, notice there is no .sh bash extension. I had a problem with the extension which caused the script to not run.

输入该进入命令行的文本编辑器纳米

Enter this into the command line text editor nano

#!/bin/bash

php /var/www/mail-script.php > /var/www/mail-script-log.txt

现在将文本文件保存并退出,节省使用 CTRL + O 然后preSS进入,退出preSS CTRL + X

Now save the text file and exit, to save use CTRL + O and then press enter, to exit press CTRL + X.

我们需要让文件被执行时,键入 sudo的搭配chmod + X mailscript

We need to allow the file to be executed, type sudo chmod +x mailscript.

要测试它的类型 ./ mailscript 来运行 cron.daily 的cron的。现在检查你的电子邮件!

To test it out type ./mailscript to run the cron in cron.daily. Now check your emails!

这篇关于无法在Amazon EC2上设置的cron作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆