Crontab is not working on Amazon EC2 server

时间:2023-01-26 12:14:15

Crontab is not working on Amazon EC2 Linux Server.

Crontab无法在Amazon EC2 Linux Server上运行。

I have saved below codes in /etc/crontab file

我在/ etc / crontab文件中保存了以下代码

crontab
# For details see man 4 crontabs 
# Example of job definition: 
# .---------------- minute (0 - 59) 
# | .------------- hour (0 - 23) 
# | | .---------- day of month (1 - 31) 
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ... 
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat 
# | | | | | 
# * * * * * user-name command to be executed 
* 10 * * * tar cvfpz /home/backup/web_$(date +%Y%m%d).tar.gz /home/web

I have started crontab command already, but this one didn't work.

我已经启动了crontab命令,但是这个没有用。

I also have saved this line in "crontab -e" too, but cron won't work.

我也在“crontab -e”中保存了这一行,但是cron不起作用。

* 10 * * * tar cvfpz /home/backup/web_$(date +%Y%m%d).tar.gz /home/web

Is there anyone who had same experience like me?

有没有像我这样的经历?

Thank you.

3 个解决方案

#1


1  

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

#2


0  

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://*.com/a/16986464/1777152

您应该使用crontab -e为已记录的用户创建cron,这样您就不需要通知用户名。请参见此处:https://*.com/a/16986464/1777152

#3


0  

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.

我最近开始在ec2实例上使用亚马逊的Linux发行版,在为cron尝试各种各样的东西后,我需要的是:sudo service crond start crontab -e这允许我将cron作业设置为“ec2-user”而不指定用户。例如:0 12 * * * python3 example.py实际上,在此处指定用户会阻止它运行。

#1


1  

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

#2


0  

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://*.com/a/16986464/1777152

您应该使用crontab -e为已记录的用户创建cron,这样您就不需要通知用户名。请参见此处:https://*.com/a/16986464/1777152

#3


0  

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.

我最近开始在ec2实例上使用亚马逊的Linux发行版,在为cron尝试各种各样的东西后,我需要的是:sudo service crond start crontab -e这允许我将cron作业设置为“ec2-user”而不指定用户。例如:0 12 * * * python3 example.py实际上,在此处指定用户会阻止它运行。