sed的结果赋值给一个变量后输出结果不正常 10
写了一个生成随机ip的shell脚本,但是输出结果老是不正常,请大神看看#!/bin/bash#writebycmw#thisshellusetouploadweb/wa...
写了一个生成随机ip的shell脚本,但是输出结果老是不正常,请大神看看
#!/bin/bash
# write by cmw
# this shell use to upload web/wap uv/pv
REMOTE_DIR=gdcn
LOCAL_DOWN_DIR=/data/uploadfiles
LOCAL_UP_DIR=/data/dumpfiles
FILENAME=`date -d last-day +%Y%m%d`
S1=_web.txt
UP_FILES=$FILENAME$S1
yyyymmdd=`date -d last-day +%Y-%m-%d`
aa=${aa:="1 27427"}
bb=${bb:="1 254"}
hh=${hh:="1 24"}
mi=${mi:="1 59"}
ss=${ss:="1 59"}
ii=${ii:="1 3"}
zz=`seq $ii | while read i;do echo "$i $RANDOM";done | sort -k2n | cut -d" " -f1 | tail -1`
for i in `seq $zz`
do
a=`seq $aa | while read i;do echo "$i $RANDOM";done | sort -k2n | cut -d" " -f1 | tail -1`
b=`seq $bb | while read i;do echo "$i $RANDOM";done | sort -k2n | cut -d" " -f1 | tail -1`
c=`sed -n ${a}p gdip.txt`
e=`seq -f"%02g" $hh | while read i;do echo "$i $RANDOM";done | sort -k2n | cut -d" " -f1 | tail -1`
f=`seq -f"%02g" $mi | while read i;do echo "$i $RANDOM";done | sort -k2n | cut -d" " -f1 | tail -1`
g=`seq -f"%02g" $ss | while read i;do echo "$i $RANDOM";done | sort -k2n | cut -d" " -f1 | tail -1`
echo "$c.$b">>$LOCAL_UP_DIR/${FILENAME}_web.txt
done
结果
.91253.112
.218104.12
'.24114.75
补充下,文件gdip.txt里是前三个ip段,比如14.18.160 展开
#!/bin/bash
# write by cmw
# this shell use to upload web/wap uv/pv
REMOTE_DIR=gdcn
LOCAL_DOWN_DIR=/data/uploadfiles
LOCAL_UP_DIR=/data/dumpfiles
FILENAME=`date -d last-day +%Y%m%d`
S1=_web.txt
UP_FILES=$FILENAME$S1
yyyymmdd=`date -d last-day +%Y-%m-%d`
aa=${aa:="1 27427"}
bb=${bb:="1 254"}
hh=${hh:="1 24"}
mi=${mi:="1 59"}
ss=${ss:="1 59"}
ii=${ii:="1 3"}
zz=`seq $ii | while read i;do echo "$i $RANDOM";done | sort -k2n | cut -d" " -f1 | tail -1`
for i in `seq $zz`
do
a=`seq $aa | while read i;do echo "$i $RANDOM";done | sort -k2n | cut -d" " -f1 | tail -1`
b=`seq $bb | while read i;do echo "$i $RANDOM";done | sort -k2n | cut -d" " -f1 | tail -1`
c=`sed -n ${a}p gdip.txt`
e=`seq -f"%02g" $hh | while read i;do echo "$i $RANDOM";done | sort -k2n | cut -d" " -f1 | tail -1`
f=`seq -f"%02g" $mi | while read i;do echo "$i $RANDOM";done | sort -k2n | cut -d" " -f1 | tail -1`
g=`seq -f"%02g" $ss | while read i;do echo "$i $RANDOM";done | sort -k2n | cut -d" " -f1 | tail -1`
echo "$c.$b">>$LOCAL_UP_DIR/${FILENAME}_web.txt
done
结果
.91253.112
.218104.12
'.24114.75
补充下,文件gdip.txt里是前三个ip段,比如14.18.160 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询