Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
613 views
in Technique[技术] by (71.8m points)

unix - Cannot get cron to work on Amazon EC2?

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.

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/

My crontab file looks like this:

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

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.

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

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?

Thanks for your time.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

  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.

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...