On Sat, Dec 04, 2010 at 10:01:35AM +0330, hadi motamedi wrote: > Dear All > On my Debian server, I need to separate the individual logs coming > from various modules concurrently. Please find below a sample of the > logs: > ' IPTR >.. > > Read Subscript: 153 Write Subscript: 154 Port: 4972 > Current time: Tue Nov 23 15:33:53 2010 > Sent packet to 172.18.99.1 4972 #0 > packet is 1081 bytes long, contains: > 30 82 04 35 02 01 01 04 06 70 75 62 6C 69 63 A7 82 04 26 02 01 01 02 > 01 FF 02 0107 30 82 04 19 30 82 04 15 06 0F 2B 06 01 04 01 8A 5D 01 03 > 03 04 02 07 AE 0B 0482 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 > 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 > > SNMP >.. > > local:4972 ==> 172.18.99.1:4972 Type=Trap-V2, RID=136337360, > Error=255, Bind=1[37m > oid[0]=1.3.6.1.4.1.1373.1.3.3.4.2.7.5899, vartype=04, msglen=1024 > > local:4969 ==> 172.18.99.1:4969 Type=Trap-V2, RID=1, Error=80, Bind=1[37m > oid[0]=1.3.6.1.4.1.1373.1.3.3.8.2.7.779, vartype=04, msglen=1024 > > HLR >.. > > HLR recv <- DELIM ind > Dialogue id:1927' > As you see, each log begins with its modules name that I need to > separate its individual log. So I have wrote the following code to > separate it: > #cat Edit3 | tr -d "\r" | while read LINE; do > >echo "$LINE" | grep -q '>\.\.' > >if [ $? -eq 0 ]; then > >LOGFILE=`echo $LINE | cut -d' ' -f1`.log > >else > >echo "$LINE" >> $LOGFILE > >fi > >done > But when I run it, I am receiving the following error: > -bash: -f1.log : command not found > -bash: $LOGFILE : ambiguous redirect > Can you please help me to correct my code? > Thank you
Hello, I gave it a try doing the following: a) create a script: $ cat test.sh #!/bin/bash - cat test.txt | tr -d "\r" | while read LINE; do echo "$LINE" | grep -q '>\.\.' if [ $? -eq 0 ]; then LOGFILE=`echo $LINE | cut -d' ' -f1`.log else echo "$LINE" >> $LOGFILE fi done b) this is the log sample: $ cat test.txt IPTR >.. Read Subscript: 153 Write Subscript: 154 Port: 4972 Current time: Tue Nov 23 15:33:53 2010 Sent packet to 172.18.99.1 4972 #0 packet is 1081 bytes long, contains: 30 82 04 35 02 01 01 04 06 70 75 62 6C 69 63 A7 82 04 26 02 01 01 02 01 FF 02 0107 30 82 04 19 30 82 04 15 06 0F 2B 06 01 04 01 8A 5D 01 03 03 04 02 07 AE 0B 0482 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 SNMP >.. local:4972 ==> 172.18.99.1:4972 Type=Trap-V2, RID=136337360, Error=255, Bind=1 oid[0]=1.3.6.1.4.1.1373.1.3.3.4.2.7.5899, vartype=04, msglen=1024 local:4969 ==> 172.18.99.1:4969 Type=Trap-V2, RID=1, Error=80, Bind=1 oid[0]=1.3.6.1.4.1.1373.1.3.3.8.2.7.779, vartype=04, msglen=1024 HLR >.. HLR recv <- DELIM ind Dialogue id:1927' c) run the test and inspect the results: $ ./test.sh; ls -lrt *.log -rw------- 1 dawud dawud 293 dic 4 11:48 SNMP.log -rw------- 1 dawud dawud 924 dic 4 11:48 IPTR.log -rw------- 1 dawud dawud 41 dic 4 11:48 HLR.log $ for a in *.log; do printf "$a--->\n"; cat $a; done HLR.log---> HLR recv <- DELIM ind Dialogue id:1927' IPTR.log---> Read Subscript: 153 Write Subscript: 154 Port: 4972 Current time: Tue Nov 23 15:33:53 2010 Sent packet to 172.18.99.1 4972 #0 packet is 1081 bytes long, contains: 30 82 04 35 02 01 01 04 06 70 75 62 6C 69 63 A7 82 04 26 02 01 01 02 01 FF 02 0107 30 82 04 19 30 82 04 15 06 0F 2B 06 01 04 01 8A 5D 01 03 03 04 02 07 AE 0B 0482 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 SNMP.log---> local:4972 ==> 172.18.99.1:4972 Type=Trap-V2, RID=136337360, Error=255, Bind=1 oid[0]=1.3.6.1.4.1.1373.1.3.3.4.2.7.5899, vartype=04, msglen=1024 local:4969 ==> 172.18.99.1:4969 Type=Trap-V2, RID=1, Error=80, Bind=1 oid[0]=1.3.6.1.4.1.1373.1.3.3.8.2.7.779, vartype=04, msglen=1024 I'm using: $ echo $BASH_VERSION 4.1.5(1)-release Are these the results you expect? -- Huella de clave primaria: 0FDA C36F F110 54F4 D42B D0EB 617D 396C 448B 31EB
signature.asc
Description: Digital signature