[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: please correct me on my code?



On Sat, 04 Dec 2010 10:01:35 +0330, hadi motamedi wrote:

> 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 >..

(...)

> 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

Your script runs quite fine here without any modification :-?

sm01@stt008:~/Desktop$ cat test.sh
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
sm01@stt008:~/Desktop$ sh ./test.sh
sm01@stt008:~/Desktop$ cat *.log

HLR recv <- DELIM ind
Dialogue id:1927'

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


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

sm01@stt008:~/Desktop$ ls -l | grep log
-rw-r--r-- 1 sm01 sm01    41 dic  4 12:02 HLR.log
-rw-r--r-- 1 sm01 sm01   924 dic  4 12:02 IPTR.log
-rw-r--r-- 1 sm01 sm01   293 dic  4 12:02 SNMP.log


Greetings,

-- 
Camaleón


Reply to: