1.给shell脚本里面加入时间。
d=`date +%Y-%m-%d`
echo -e "当前时间:$d" >>time.txt
2.crontab的简单使用。
cat /etc/crontab #查看crontab,输出如下所示
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- 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 command to be executed
crontab -l #查看当前用户下的crontab命令。
crontab -e #写入需要执行的crontab命令。
30 5 * * 5 sh 绝对路径/log.sh 2>&1 #表示每周五5点半执行sh脚本。
写的shell脚本一定要把自己的环境变量写进去,或者source自己的环境变量加入脚本中,要不然可能会报错。