LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-14-2010, 10:53 AM   #1
sebelk
Member
 
Registered: Jan 2007
Posts: 66

Rep: Reputation: 15
IFS problem?


Hi,

if I issue command

Code:
grep   TLS.*denied /var/log/radius/radius.log
it ouputs:


Thu May 13 19:12:44 2010 : Error: TLS Alert read:fatal:access denied
Thu May 13 19:14:37 2010 : Error: TLS Alert read:fatal:access denied
Thu May 13 19:20:07 2010 : Error: TLS Alert read:fatal:access denied
Thu May 13 19:47:23 2010 : Error: TLS Alert read:fatal:access denied
Fri May 14 08:01:21 2010 : Error: TLS Alert read:fatal:access denied
Fri May 14 10:44:58 2010 : Error: TLS Alert read:fatal:access denied
Fri May 14 11:45:15 2010 : Error: TLS Alert read:fatal:access denied


So I've wrote the following script:

Code:
#! /bin/bash

for i in "$(grep   TLS.*denied /var/log/radius/radius.log| awk -F' : ' '{print $1}')"
   do
      IFS=$(echo -e '\n')

      filedate=$(date -d  $i '+%Y%m%d')
      hourtry=$(date -d $i '+%H%M%s')
      grep  "$hourtry" /var/log/radius/radiusd-DEFAULT-$filedate.log
   done

unset IFS

But I get:

date: invalid date `Wed May 5 15:51:59 2010\nWed May 5 16:10:08 2010\nWed May 5 16:31:44 2010\nWed May 5 17:20:18 2010\nWed May 5 19:07:48 2010\nWed May 5 19:10:10 2010\nWed May 5 19:55:57 2010\nWed May 5 21:51:53 2010\nThu May 6 07:52:29 2010\nThu May 6 07:56:56 2010\nThu May 6 07:59:07 2010\nThu May 6 08:05:14 2010\nThu May 6 08:07:28 2010\nThu May 6 08:08:41 2010\nThu May 6 08:09:15 2010\nThu May 6 08:10:03 2010\nThu May 6 08:10:32 2010\nThu May 6 08:11:52 2010\nThu May 6 08:13:35 2010\nThu May 6 08:20:49 2010\nThu May 6 08:26:44 2010\nThu May 6 09:16:09 2010\nThu May 6 09:18:29 2010\nThu May 6 09:20:58 2010\nThu May 6 09:22:14 2010\nThu May 6 09:55:10 2010\nThu May 6 11:17:21 2010\nThu May 6 12:03:41 2010\nThu May 6 12:04:31 2010\nThu May (...) Fri May 14 08:01:21 2010\nFri May 14 10:44:58 2010\nFri May 14 11:45:15 2010'
grep: /var/log/radius/radiusd-DEFAULT-.log: No such file or directory


(I've shortened the output)

I've tried using IFS=$'\n' but id didn't work either. What am I doing wrong?

Thanks in advance, Greetings
 
Old 05-14-2010, 11:05 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
The double quotes around $( ) in for i in "$(grep TLS.*denied /var/log/radius/radius.log| awk -F' : ' '{print $1}')" result in a single word instead of several words being the date+time-stamps you want from the TLS messages. Because the date+time-stamps of the TLS messages include spaces it will not work without the double quotes either so the script will need to process the grep output a line at a time, something like this (not tested)
Code:
while read line
do
   date_time=${line%% :*}
   whatever else you want to do
done <<< "$( grep 'TLS.*denied' /var/log/radius/radius.log )"

Last edited by catkin; 05-14-2010 at 11:06 AM. Reason: comprehensibility
 
Old 05-14-2010, 12:45 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Or you could stick with just the awk depending on if the rest of the line is important:
Code:
while read line
do 
    filedate=$(date -d "$line" '+%Y%m%d')
    <other stuff>
done < <(awk -F" : " '{print $1}' log)
 
Old 05-17-2010, 08:20 AM   #4
sebelk
Member
 
Registered: Jan 2007
Posts: 66

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by catkin View Post
The double quotes around $( ) in for i in "$(grep TLS.*denied /var/log/radius/radius.log| awk -F' : ' '{print $1}')" result in a single word instead of several words being the date+time-stamps you want from the TLS messages. Because the date+time-stamps of the TLS messages include spaces it will not work without the double quotes either so the script will need to process the grep output a line at a time, something like this (not tested)
Code:
while read line
do
   date_time=${line%% :*}
   whatever else you want to do
done <<< "$( grep 'TLS.*denied' /var/log/radius/radius.log )"
That didn't work

"-bash: Wed May 5 15:51:59 2010 : Error: TLS Alert read:fatal:access denied "

and it ends ouputs with:

"Mon May 17 10:07:47 2010 : Error: TLS Alert read:fatal:access denied : File name too long"
 
Old 05-17-2010, 08:23 AM   #5
sebelk
Member
 
Registered: Jan 2007
Posts: 66

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by grail View Post
Or you could stick with just the awk depending on if the rest of the line is important:
Code:
while read line
do 
    filedate=$(date -d "$line" '+%Y%m%d')
    <other stuff>
done < <(awk -F" : " '{print $1}' log)
Hi, sadly it didn't worked either:

Code:
while read line; do  filedate=$(date -d "$line" '+%Y%m%d'); echo $filedate; done << (awk -F" : " '{print $1}' /var/log/radius/radius.log)
-bash: syntax error near unexpected token `('
 
Old 05-17-2010, 09:11 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by sebelk View Post
Hi, sadly it didn't worked either:

Code:
while read line; do  filedate=$(date -d "$line" '+%Y%m%d'); echo $filedate; done << (awk -F" : " '{print $1}' /var/log/radius/radius.log)
-bash: syntax error near unexpected token `('
Because you had
Code:
done << (
instead of
Code:
done < <(
 
  


Reply

Tags
bash, ifs



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
setting IFS to ignore pattern eRJe Programming 3 03-12-2010 04:20 AM
list graphics only for a IFS loop wonderfullyrich Programming 5 12-30-2009 09:46 AM
Procmail and IFS cipher7836 Linux - Newbie 2 08-05-2009 11:13 AM
Ifs Gins Programming 2 07-18-2006 04:01 AM
setting IFS variable infamous41md Linux - Newbie 2 05-20-2003 06:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:16 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