【crontab】使用cron每天定时签到掘金

一、场景

    每天自动掘金签到

 

 

二、crontab工具

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)
* * * * * command
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
复制代码
$ crontab -l
# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command
复制代码

 

三、添加定时任务

输入crontab -e进入编辑模式

然后添加定时任务

 然后按下Ctrl + o,保存写入

 然后回车保存

 按住Ctrl +x离开

检查添加是否成功,可以使用crontab -l 查看

 

四、验证查看

 可以看到今日已签到

查看执行日志

journalctl -u cron.service

按下Shift+g调到最后

 或者,搜索使用 grep 搜索 cron 日志

grep CRON /var/log/syslog

 

参考链接:

https://blog.csdn.net/weixin_35757191/article/details/129084740

 

posted @   代码诠释的世界  阅读(38)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示