无法让 cron 在 Amazon EC2 上工作? [英] Cannot get cron to work on Amazon EC2?

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

问题描述

我花了两天时间试图理解为什么我无法让 cron 在我的 Ubuntu EC2 实例上工作.我已阅读文档.任何人都可以帮忙吗?我想要的只是获得一份工作的 cronjob.

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 working cronjob.

我正在使用一个简单的 wget 命令来测试 cron.我已经验证这可以从命令行手动工作:

I am using a simple wget command to test cron. I have verified that this works manually from the command line:

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

我的 crontab 文件如下所示:

My crontab file looks like this:

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

我在命令之间有一个空格,并且在命令下方有一个空行.我还尝试从系统级别 sudo crontab -e 执行此命令.它仍然不起作用.

I have single spaces between the commands and I have a blank line below the command. I've also tried to execute this command from the system level sudo crontab -e. It still doesn't work.

cron 守护进程正在运行:

The cron daemon is running:

ps aux | grep crond                                                                                                                   
ubuntu    2526  0.0  0.1   8096   928 pts/4    S+   10:37   0:00 grep crond

cronjob 似乎正在运行:

The cronjob appear to be running:

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

有人有任何建议或可能的解决方案吗?

Does anyone have any advice or possible solutions?

感谢您的时间.

推荐答案

Cron 可以在基于 Amazon 的 linux 服务器中运行,就像在任何其他 linux 服务器中一样.

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

  1. 使用 SSH 登录控制台.
  2. 在命令行上运行 crontab -e.
  3. 您现在位于当前用户(默认为控制台用户,具有 root 权限)的 crontab 的 vi 编辑器中
  4. 要测试 cron,请添加以下行:* * * * */usr/bin/uptime >/tmp/uptime
  5. 现在保存文件并退出 vi(按 Esc 并输入 :wq).
  6. 一两分钟后,检查是否在/tmp (cat/tmp/uptime) 中创建了正常运行时间文件.
  7. 通过在命令行中输入 uptime 命令将其与当前系统正常运行时间进行比较.
  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.

上述场景在安装了 Amazon Linux O/S 的服务器上成功运行,但它也应该在其他 linux 机器上运行.这会修改当前用户的 crontab,而不会触及系统的 crontab,并且不需要用户在 crontab 条目中,因为您是在自己的用户下运行的.更轻松、更安全!

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!

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

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