零基础Linux定时shell脚本
2014-10-21 12:59
267 查看
废话不多说,步骤一步一步来!
第一步:编写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/;以及我的一位好朋友!
第一步:编写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/;以及我的一位好朋友!
相关文章推荐
- linux 定时执行shell脚本
- linux基础之简单shell脚本编写
- Linux新手生存笔记[8]——shell脚本基础1-变量
- shell脚本兼容linux/unix与windows/cygwin的基础(注意处理好CR, LF, CR/LF 回车 换行的问题)
- Linux——Shell管理脚本(基础详解--精)
- Linux 怎么通过shell脚本定时备份mysql数据库
- Linux Bash Shell学习(七):shell编程基础——运行Shell脚本、function
- Linux新手生存笔记[9]——shell脚本基础2-条件测试及控制流
- LinuxC/C++编程基础(13) shell脚本简单实例
- Linux新手生存笔记[11]——shell脚本基础4-补充
- linux脚本编写基础(环境变量、shell流程控制)
- Linux新手生存笔记[10]——shell脚本基础3-函数及常用命令
- linux 基础学习之四:shell脚本学习(1)
- Linux新手生存笔记[10]——shell脚本基础3-函数及常用命令
- Linux新手生存笔记[9]——shell脚本基础2-条件测试及控制流
- linux 定时执行shell脚本详解
- linux基础学习-shell脚本学习(鸟哥私房菜)
- Linux新手生存笔记[10]——shell脚本基础3-函数及常用命令
- linux 定时执行shell脚本
- Linux新手生存笔记[11]——shell脚本基础4-补充