- 论坛徽章:
- 0
|
原脚本 请大侠们忙吧 sed 执行不了
#!/bin/sh
YYYY=`date "+%Y"`
MM=`date "+%m"`
DD=`date "+%d"`
riqi='['${DD}"/"${MM}"/"${YYYY}' '
tihuan='/['${DD}"/"${MM}"/"${YYYY}':'
pre_filename="access.log"
yuanfile="${pre_filename}${YYYY}${MM}${DD}.log"
cd /var/logs
olddate=$riqi$tihuan
/bin/sed 's/'$olddate'/' access.log.0 > $yuanfile
debug运行结果如下
./squidlog
++ date +%Y
+ YYYY=2008
++ date +%m
+ MM=06
++ date +%d
+ DD=19
+ riqi='[19/06/2008 '
+ tihuan='/[19/06/2008:'
+ pre_filename=access.log
+ yuanfile=access.log20080619.log
+ cd /var/logs
+ olddate='[19/06/2008 /[19/06/2008:'
+ /bin/sed 's/[19/06/2008' '/[19/06/2008:/' access.log.0
/bin/sed: -e expression #1, char 13: unterminated `s' command
[root@FL118114 logs]# /bin/sed 's/[19/06/2008 /[19/06/2008:/' access.log.0 > log1
/bin/sed: -e expression #1, char 28: unterminated `s' command
可是我/bin/sed 's/[19/06/2008 /[19/06/2008:/' access.log.0 >log 手动执行也不行
/bin/sed 's/2008 /2008:/' access.log20080619 > log 我这样执行又是可以的
[ 本帖最后由 power328 于 2008-6-19 13:59 编辑 ] |
|