Mở trình soạn thảo sửa file crontab
sudo vim /etc/crontab
Sửa nhanh bằng lệnh
crontab -e
Hoặc sửa bằng đường dẫn trực tiếp
sudo vi /var/spool/cron/user
Một số lệnh thường dùng
crontab -e: tạo hoặc chỉnh sửa file crontab
crontab -l: hiển thị file crontab
crontab -r: xóa file crontab
Nơi lưu trữ crontab /var/spool/cron/crontabs
Ý nghĩa các tham số trong crontab lệnh
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name <lệnh cần gọi>
Lệnh backup database từng phút
* * * * * mysqldump -u dbusername -p'dbpassword' dbname > /path/to/file/backup.sql