废话不多说,步骤一步一步来!
第一步:编写shell脚本。目录/home/hou/test.sh;新建文件test.sh,脚本内容:
#!/bin/bash
echo "Hello World !"
保存退出!
第二步:赋权限给shell脚本。cd到当前目录,“chmod +x ./test.sh“ #赋给shell脚本权限,"./test.sh" #执行shell脚本。
第三步:加入到crontab的定时序列里。"vim /ect/crontab",在最后一行添加" */1 * * * * /home/hou/test.sh >> /home/hou/test.log 2>&1 ";这句话的意思是每分钟执行一次test.sh脚本,并把结果输出到/home/hou/目录下的test.log,其他的都是固定的格式,时间格式请参考其他大神的博客,保存退出,如果不放心crontab能够执行的话,建议"
crontab -e"把这句话插入进去,保存退出。
第四步:重启crontab服务。" /sbin/service crond restart "或者" service crond restart "。
第五部:查看输入的内容。"tail -f /home/hou/test.log",如果看到"hello word!"那就说明成功了!
参考:http://see.xidian.edu.cn/cpp/view/6998.html;http://www.2cto.com/os/201310/248480.html;http://see.xidian.edu.cn/cpp/shell/;以及我的一位好朋友!