在AWS EC2实例中设置Cron Job [英] Setting Cron Job in AWS EC2 instance
问题描述
我已经在AWS EC2中创建了一个cron作业,但是它不起作用.
I've created a cron job in AWS EC2 but it is not working.
我按照以下步骤创建了cron标签:
I followed below steps to create cron tab:
步骤1:我登录到AWS EC2 Instace
Step 1: I logged in to AWS EC2 Instace
第2步:须藤su
第2步:crontab -e
step 2: crontab -e
第3步:插入模式
第4步:我输入
# M H DOM M DOW CMND
15 14 * * 3 /services/backup.sh >/tmp/error.log 2>&1
第5步:: wq Cron标签已创建但未运行.
Step 5: :wq Cron tab is created but not running.
请问有人可以帮助我,为什么它不起作用?
Please can you any one help me , why it is not working?
更新:
经过大量研究,我发现我可以为特定的cron文件提供日志,因此在文件中添加了>/tmp/error.log 2>& 1并在其中创建了error.log.
after lots of researching i found that i can give a log to the particular cron file so added >/tmp/error.log 2>&1 in my file and created error.log there.
但是我在那里没有任何cron日志.现在我认为我的cron文件没有运行(显然它没有运行).
but i am not getting any cron log there. now i think my cron file is not running(obviously it is not running).
但是如何查看我是否缺少
but how to see whether i am lacking
当我检查cron服务时,它以名称crond
and when i checked cron service it is running with the name crond
service crond status
crond (pid 28283) is running...
(backup.sh脚本绝对运行正常)
(backup.sh script absolutely running fine)
推荐答案
您能否在cron中尝试backup.sh的完整路径,如下所示;您可以使用pwd命令查找脚本的完整路径.
could you try full path of backup.sh in cron like below; you can use pwd command to find full path of your script.
# M H DOM M DOW CMND
25 12 * * 3 /home/user/script/backup.sh
也许您的cron服务未启动,您可以使用"ps -ef | grep cron | grep -v grep"检查状态
Maybe, your cron service not started, you can check status with "ps -ef | grep cron | grep -v grep"
如果看不到任何东西在运行;
if not see any thing run this;
sudo service cron start
如果运行;更改cron如下:
if run; change cron as below;
15 13 * * 3 root /fullpath/backup.sh >/tmp/error.log 2>&1
然后您检查error.log
then you check error.log
>/tmp/error.log 2>& 1是; 将程序的输出重定向到/tmp/error.log.同时包括标准错误和标准输出
>/tmp/error.log 2>&1 is; redirect the output of your program to /tmp/error.log. Include both the Standard Error and Standard Out
这篇关于在AWS EC2实例中设置Cron Job的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!