[英]Unable to setup cron-job on Amazon EC2
I have an Amazon EC2 instance (Ubuntu Server 13.04 - 64 bit [ami-bf1d8a8f]) running my website. 我有一个运行我的网站的Amazon EC2实例(Ubuntu Server 13.04 - 64位[ami-bf1d8a8f])。 I need to setup a Cron Job to get an email alert everyday.
我需要设置一个Cron Job来每天收到一封电子邮件提醒。
Does anyone have any advise or possible solutions? 有没有人有任何建议或可能的解决方案?
Thanks for your time. 谢谢你的时间。
It's just the same as setting up a cron job on any other server via command line. 它与通过命令行在任何其他服务器上设置cron作业相同。
/etc/cron.daily
/etc/cron.daily
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 -q -O temp.txt http://www.site.com/cron.php
类的命令来调用PHP脚本,或者通过命令行php /var/www/site/cron.php
。
Regarding the wget
method, temp.txt
will contain the output of the script, or you can redirect the output to /dev/null
. 关于
wget
方法, temp.txt
将包含脚本的输出,或者您可以将输出重定向到/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
如果你需要保存cron脚本的输出而你决定使用命令行方法,那么你可以将数据输出到文件
php /var/www/site/cron.php > output.txt
If you need more explanation/detail post a comment. 如果您需要更多解释/详细信息发表评论。 Also take a look at Basic cron job set up to execute php file daily
另外看看Basic cron job设置每天执行php文件
cron.daily
folder cron.daily
文件夹中创建一个bash脚本 Connect to the instance via SSH, navigate to the daily cron folder with cd /etc/cron.daily
. 通过SSH连接到实例,使用
cd /etc/cron.daily
导航到每日cron文件夹。 Next type sudo nano mailscript
, notice there is no .sh
bash extension. 接下来输入
sudo nano mailscript
,注意没有.sh
bash扩展名。 I had a problem with the extension which caused the script to not run. 我的扩展程序有问题导致脚本无法运行。
Enter this into the command line text editor nano
在命令行文本编辑器
nano
输入此项
#!/bin/bash
php /var/www/mail-script.php > /var/www/mail-script-log.txt
Now save the text file and exit, to save use CTRL + O
and then press enter, to exit press CTRL + X
. 现在保存文本文件并退出,保存使用
CTRL + O
然后按Enter键退出按CTRL + X
We need to allow the file to be executed, type sudo chmod +x mailscript
. 我们需要允许执行文件,输入
sudo chmod +x mailscript
。
To test it out type ./mailscript
to run the cron in cron.daily
. 要测试它,请输入
./mailscript
以在cron.daily
运行cron。 Now check your emails! 现在查看你的电子邮件!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.