How to execute a task automatically?For example,updating news or graping web pages.We can do as below.
###1.install cron
sudo apt-get install cron
###2.find out whether cron runs
pgrep cron
if you can see a list of pids,cron runs successfully.if not,run:
service cron start
###3.add a automatically task
Now,we can edit a profile which storing information for a automatically task.
Run:
crontab -e
then, we choose a edit ide to edit this profile.
m h dom mon dow command
0-59 0-23 1-31 1-12 0-7 command
dom means day of month.
for example:
59 * * * * java -jar /home/ruben/update_news.jar
other command list below:
usage: crontab [-u user] file
crontab [ -u user] [ -i ] { -e | -l | -r }
(default operation is replace, per 1003.2)
-e (edit user's crontab)
-l (list user's crontab)
-r (delete user's crontab)
-i (prompt before deleting user's crontab)
if you want to see cron log,you can run:
grep CRON /var/log/syslog
/*note that CRON is upcase.*/
then,you can see a list of log info in the screen.
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于