crontab的使用
# 进入crontab
crontab -e
# 查看crontab内容
crontab -l
# 参数介绍
分 小时 日 月 星期 命令
0-59 0-23 1-12 0-6 0-6 command
例: */15 * * * * ls 每十五分钟执行ls
0 */2 * * * ls 每两个小时执行一次ls
* * * * * ls 每分钟执行一次ls
# 执行python程序
1. 把python的执行命令写入 .sh脚本
2. 给脚本添加可执行权限 chmod +x myspider.sh
3. 把.sh程序写入crontab配置文件中
# crontab
0 6 * * * /home/aaa/.../myspider.sh >> /home/aaa/.../run.log 2>&1
#!/bin/bash
cd `dirname $0` || exit 1
python ./spidera.py >>run.log 2>&1 # 标准错误也输出到run.log
# 其他
tail -f run.log # 可以夯住,及时显示run.log变化