如你在 /etc/crontab 文件中所见,它使用 run-parts 脚本来执行 /etc/cron.hourly、/etc/cron.daily、/etc/cron.weekly 和 /etc/cron.monthly 目录中的脚本,这些脚本被相应地每小时、每日、每周、或每月执行。这些目录中的文件应该是 shell 脚本。
如果某 cron 任务需要根据调度来执行,而不是每小时、每日、每周、或每月地执行,它可以被添加到 /etc/cron.d 目录中。该目录中的所有文件使用和 /etc/crontab 中一样的语法。
# record the memory usage of the system every monday
# at 3:30AM in the file /tmp/meminfo 30 3 * * mon cat /proc/meminfo >> /tmp/meminfo
# run custom script the first day of every month at 4:10AM 10 4 1 * * /root/scripts/backup.sh
同时在写crontab执行的.sh脚本时要注意添加权限和路径。例如:
crontab语句:30 14 * * * /opt/apps/ems_query/bin/start.sh
相应的脚本:
source /home/tvgame/.bash_profile
cd /opt/apps/ems_query/bin/
java -Xmx64M -jar ../lib/ems_query.jar &
