服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Linux - linux Crontab的一些使用提示

linux Crontab的一些使用提示

2020-03-31 18:42Linux教程网 Linux

crontab是linux vps下面常见的定时工具。它可以隔一段时间就进行一次你预期定好的命令。

可以把你需要处理的命令写成脚本,放在bats.sh里面。

使用crontab -e 进行编辑调用定时执行。

# [分钟] [小时] [一个月中的某一天] [月份] [一周中的某一天] [命令]
30 * * * * /home/netroby/backup/autobak.sh
# */30表示每 30分钟, 如果这里写的是30,那么就是每小时的30分的时候

bats.sh里面的内容示例

#!/bin/sh
export GIT_DIR=”/home/user/backup/vhosts/.git”
/usr/bin/ssh user@www.domain.com “cd /vhosts/ && ./backup.sh && git commit -am ‘backup’”
cd /home/user/backup/vhosts/
/usr/bin/git pull origin master

变量一定要导出,少了变量,程序执行就是错的。

路径要使用绝对路径,执行的目录一定要转到绝对位置。

cron的日志在/var/log/syslog里面

vim -R /var/log/syslog即可查看 cron 日志。

crontab -l列出当前安排的定时器。crontab -e 编辑定时器,可以增加或者减少 ,crontab -r 是清除定时器。

更多资料请参考:

http://wiki.ubuntu.org.cn/CronHowto

https://help.ubuntu.com/community/CronHowto

延伸 · 阅读

精彩推荐