shell如何一次读一行?
发表于 : 2010-01-21 10:26
我有一个ip.log文件
我想写一个shell脚本,一次读取ip.log文件的一行
请问要怎么写?
我想写一个shell脚本,一次读取ip.log文件的一行
请问要怎么写?
对阿对啊eexpress 写了:分析log? 那通常用bash是折腾。换其他的脚本吧。
代码: 全选
with open('your_file') as f:
line = f.readline().strip()
blabla...
代码: 全选
1 #! /bin/sh
2 # [email protected]
3 getiplist()
4 {
5 URL="http://192.168.1.191/iptv.php"
6 echo [$URL]
7 wget $URL -O ip.log
8 }
9
10 setcommands(){
11 command0="cd /"
12 command1="rm -rf /A6emenu.tgz"
13 command2="/emenu/shelldir/kill.sh"
14 command3="mv /emenu /bak.emenu"
15 command4="wget --ftp-user=test --ftp-password=test ftp://192.168.1.109/A6emenu.tgz"
16 command5="tar zxvf /A6emenu.tgz"
17 command6="/emenu/update.sh > /update.log"
18 command7="cp /bak.emenu/etc/* /emenu/etc/ -rf"
19 }
20
21 createfile(){
22 INPUT="commands"
23 OUTPUT="out.log"
24 rm -rf $INPUT
25 mknod $INPUT p
26 exec 3<>$OUTPUT
27 exec 4<>$INPUT
28 }
29
30 autotelnet(){
31 telnet $IP <&4 >&3 &
32 echo $command0 > $INPUT
33 echo $command1 > $INPUT
34 echo $command2 > $INPUT
35 echo $command3 > $INPUT
36 echo $command4 > $INPUT
37 echo $command5 > $INPUT
38 echo $command6 > $INPUT
39 echo $command7 > $INPUT
40 echo "exit" > $INPUT
41 }
42 printmessage(){
43 tail -f $OUTPUT &
44 }
45
46 loopscript(){
47 while read IP;do
48 IP="$IP 1234"
49 echo "start telnet ... {$IP} please wait"
50 autotelnet
51 done < "ip.log"
52 }
53
54 getiplist
55 setcommands
56 createfile
57 printmessage
58 loopscript
搞个文本分析的确要知道挺多种语言的……t3swing 写了:搞个文本分析还要学那么多种语言