1.新建須要定時執行的shell腳本,這裏爲date.sh腳本。shell
#!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH echo "hello world" echo "----------------------------------------------------------------------------" endDate=`date +"%Y-%m-%d %H:%M:%S"` echo "★[$endDate] Successful" echo "當前時間":$(date +"%Y-%m-%d %H:%M:%S") >> /www/wwwroot/date.txt echo "----------------------------------------------------------------------------"
2.將這個date.sh腳本添加到定時任務中,直接運行「crontab -e」命令添加就行。bash
[root@localhost ~]# crontab -e */1 * * * * /www/wwwroot/date.sh > /dev/null 2>&1 */1 * * * * /www/wwwroot/date.sh >> /www/wwwroot/result.txt 2>&1 # 天天10:30執行 30 10 * * * /www/wwwroot/date.sh
3.最後,咱們再查看一下輸出文件date.txt和crontab日誌。日誌
[root@localhost ~]# tail -n 5 /www/wwwroot/date.txt [root@localhost ~]# tail -f /var/log/cron