LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-03-2010, 11:22 PM   #1
hadimotamedi
Member
 
Registered: Aug 2009
Posts: 228

Rep: Reputation: 30
please correct me on my code?


Dear All
On my Linux 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
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'
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
 
Old 12-04-2010, 01:12 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
Assuming you typed it in correctly (as putting all on the cmd line is difficult) I see no real issues.
I placed it in a script as follows:
Code:
#!/bin/bash

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
Just made it a little easier to read. This did manage to create the 3 log files (if there really is a single quote before IPTR then that will also be the name of the file).

One gotcha I could see is that if the log should have an entry prior to a log file name (ie HLR >..) then the variable LOGFILE will have no value.

The f1.log error, my only guess here is that you used a quote instead of a back tick.
I believe the second error is just a flow on of the first so once it is solved the second should also disappear.

Hope that helps.
 
Old 12-04-2010, 01:29 AM   #3
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
I also had no problems with this, though I did modify it very slightly to take out the $? part:
Code:
cat Edit3 | tr -d "\r" | while read LINE; do if (echo $LINE | grep -q '>\.\.'); then LOGFILE=`echo $LINE | cut -d' ' -f1`.log; else echo "$LINE" >> $LOGFILE; fi; done
 
Old 12-04-2010, 03:47 AM   #4
hadimotamedi
Member
 
Registered: Aug 2009
Posts: 228

Original Poster
Rep: Reputation: 30
Thank you very much for your technical support. I tried for your modified code and it is successful my case here.
Thank you again
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Rows in lists on my Debian are correct/black/correct/black... eikhorsholm Linux - Desktop 1 10-01-2009 05:24 PM
User Preferences: Use HTML code instead of vB code? (vB code is overrated) stefanlasiewski LQ Suggestions & Feedback 5 07-26-2005 01:37 AM
Is this C code correct ? redsea Programming 4 10-23-2004 02:48 AM
Can you check my grub boot loader code and correct? Bensoft Kill MS Linux - Newbie 1 10-07-2003 04:42 PM
What is correct code for "Include File Function" on .asp pages gregoryfrancis Linux - General 1 02-11-2003 10:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration