免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2082 | 回复: 0
打印 上一主题 下一主题

[新手入门] exec 重定向stdout,stderr的实际应用 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-08-19 11:16 |只看该作者 |倒序浏览
#!/bin/ksh
filedate=`date +"20%y%m%d"`
myhost=`hostname`
errlog=/tmp/fixmv/stdout.log
exec 2>$errlog 1>&2
echo "error log will list here, if empty means there is no error log"
cd /TFT/1IL/CHAR
find ./ -mtime +4 -print|cut -c3-100|xargs -I {} mv {} /BKFILE/1IL/CHAR/$filedate
cd /TFT/3IL/CHAR
find ./ -mtime +4 -print|cut -c3-100|xargs -I {} mv {} /BKFILE/3IL/CHAR/$filedate
cd /TFT/AT1/CHAR
find ./ -mtime +4 -print|cut -c3-100|xargs -I {} mv {} /BKFILE/AT1/CHAR/$filedate
cd /TFT/FR1/CHAR
find ./ -mtime +4 -print|cut -c3-100|xargs -I {} mv {} /BKFILE/FR1/CHAR/$filedate
cd /TFT/FCV/CHAR
find ./ -mtime +4 -print|cut -c3-100|xargs -I {} mv {} /BKFILE/FCV/CHAR/$filedate
cd /TFT/1IL/JPG/IMAGE
find ./ -mtime +4 -print|cut -c3-100|xargs -I {} mv {} /BKFILE/1IL/JPG/IMAGE/$filedate
cd /TFT/3IL/JPG/IMAGE
find ./ -mtime +4 -print|cut -c3-100|xargs -I {} mv {} /BKFILE/3IL/JPG/IMAGE/$filedate
cd /TFT/AT1/JPG/MAP
find ./ -mtime +4 -print|cut -c3-100|xargs -I {} mv {} /BKFILE/AT1/JPG/MAP/$filedate
cd /TFT/FR1/JPG/IMAGE
find ./ -mtime +4 -print|cut -c3-100|xargs -I {} mv {} /BKFILE/FR1/JPG/IMAGE/$filedate
cd /TFT/FCV/JPG/IMAGE
find ./ -mtime +4 -print|cut -c3-100|xargs -I {} mv {} /BKFILE/FCV/JPG/IMAGE/$filedate
mail -s "$myhost fixmove error log!" mymail@myserver.com $errlog 1>&2
本来,如果没有这一段 mv文件的时候会有很多错误,如果没有重定向错误输出,默认的话会输出到屏幕
这样我们在执行脚本时就无法看到错误输出了(放在crontab里面用),使用exec修改了stdout,stderr后可
以将脚本里面所有命令执行时的错误输出存到我们指定的文件里面!
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/56521/showart_1133773.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP