Log script issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Log script issue
# 1  
Old 02-18-2016
Log script issue

I'm writing a script that will monitor in real time the log file for some messages and then kill the monitor script if it find a particular message. I have written similar type of script and its working for other logs(small log files), but for one particular log the below code is not working. I tried to debug the code and its just hanging after read line command. I have removed unbuffer and tried with tail -f log and it didn't work. Any help would be highly appreciated.

Code:
ID=$$
unbuffer tail -f Server.log | while read LINE
do
   case $LINE in
      *Thread*)
   echo $LINE | awk  -v var="SERVER1"  '{print var,$0}' | egrep -i  "Version|Configuration" >>/tmp/log.txt
   echo $LINE | awk  -v var="SERVER1"  '{print var,$0}' | egrep -i "fgfdg|hellp|message|jjjjjj" >>/tmp/log.txt
     ;;
      *Main*)
    echo $LINE | awk  -v var="SERVER1"  '{print var,$0}' | grep "Server started Successfully" >>/tmp/log.txt
    
    grep "Server started Successfully" /tmp/log.txt
    
    if [  $?  -eq  0  ]
     then
     
    kill $ID
    fi
    ;;

  esac
done


Thanks
# 2  
Old 02-18-2016
How does it differ from the working scripts?
# 3  
Old 02-18-2016
Rudic,

Search strings and log files are different. The other log file is small. I tried with cat command and it worked, but i can't use cat command, have to use tail command. Is my code OK? Any other method?

Thanks

---------- Post updated at 05:56 PM ---------- Previous update was at 04:55 PM ----------

Rudic,

I tried tail -F and it worked. One minor issue is that the below part is not working.
Code:
grep "Server started Successfully" /tmp/log.txt
    
    if [  $?  -eq  0  ]
     then
     
    kill $ID
    fi

I'm looking into it.

Thanks

Last edited by Don Cragun; 02-18-2016 at 09:02 PM.. Reason: Fix CODE tags.
# 4  
Old 02-19-2016
HOW does it NOT work? Any error messages?

Last edited by RudiC; 02-19-2016 at 02:47 AM..
# 5  
Old 02-19-2016
Quote:
Originally Posted by vinus
... ... ...
Rudic,

I tried tail -F and it worked. One minor issue is that the below part is not working.
Code:
grep "Server started Successfully" /tmp/log.txt
    
    if [  $?  -eq  0  ]
     then
     
    kill $ID
    fi

I'm looking into it.

Thanks
Just out of curiosity, why use kill $ID instead of exit?

Is the problem that you think the script is killing itself too soon? Note that you seem to be using the same log file on every run (appending to it instead of recreating it). So, once your script has completed successfully once, the grep will always find what is it looking for immediately on subsequent runs.

Last edited by Don Cragun; 02-19-2016 at 03:30 AM.. Reason: Add conjecture on possible problem.
This User Gave Thanks to Don Cragun For This Post:
# 6  
Old 02-19-2016
Did you consider doing ALL (or most, at least) of above in one go?
This User Gave Thanks to RudiC For This Post:
# 7  
Old 02-19-2016
My code is working fine . I have modified my case statement and its working as expected. Thanks

---------- Post updated at 03:17 PM ---------- Previous update was at 03:10 PM ----------

Don,

Thanks for your suggestions. Yes, i can use exit instead of kill id. The old log file will be renamed(with timestamp) on every run.


Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX Log File Content - Duplication Issue

I have a shell script with 2 run time arguments. During the execution if i got any error, then it needs to redirected to a error file and in console. Also both error and output to be redirected to a log file. Error output is getting copied to err file and getting displayed in console too. But... (2 Replies)
Discussion started by: sarathy_a35
2 Replies

2. Shell Programming and Scripting

Issue with pwd for script run by double click on script (MacOS High SIerra)

Hello, I have the following script that just archives and clears some log files. #!/bin/bash # script: archive_logs_and_clear # add date to logfile names and copy archive directory # clear logs # change to script directory cd ... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

3. Shell Programming and Scripting

Issue with awk script parsing log file

Hello All, I am trying to parse a log file and i got this code from one of the good forum colleagues, However i realised later there is a problem with this awk script, being naive to awk world wanted to see if you guys can help me out. AWK script: awk '$1 ~ "^WRITER_" {p=1;next}... (18 Replies)
Discussion started by: Ariean
18 Replies

4. Shell Programming and Scripting

Script running from another script issue

Hello All, I am ruuning the below script. userchecking.sh ########################### #! /bin/ksh NIS_SCRIPT_HOME="/mot/systems/NIS_SCRIPT_NEW" . $NIS_SCRIPT_HOME/common.env WORK_DIR="/mot/systems/scripts/" #WORK_DIR="/mot/b36376/myscripts/nis_user_automation"... (1 Reply)
Discussion started by: ajaincv
1 Replies

5. Solaris

Issue with log creation

Hi, some logs are not getting created under the required folder, which was working fine when i saw last time(15days back). Thought may be some issue with syslog deamon and did lot of R&D. Still not able to fix the bug.:wall: Is there any one to help me out ? Quick response will be appreciated.... (6 Replies)
Discussion started by: Sricharan21
6 Replies

6. Shell Programming and Scripting

Log rotation issue with script

I have application which to the heavy stdout and I have diverted the stdout to log file. this log file is writing very heavily and we have a script which rotates the logs. logic for rotation is smthing like cp logfile logfile.1 cat /dev/null > logfile this logic was working fine till we... (3 Replies)
Discussion started by: navinmistry
3 Replies

7. UNIX for Dummies Questions & Answers

(/var/log/messages) issue

Hi, I found this in my logs today for vsftpd: Nov 17 08:43:58 ftp vsftpd: Tue Nov 17 13:43:58 2009 OK LOGIN: Client "205.150.86.90" Nov 17 08:44:49 ftp avahi-daemon: Withdrawing address record for 205.111.86.22 on eth0. Nov 17 08:44:49 ftp avahi-daemon: Leaving mDNS multicast group on... (6 Replies)
Discussion started by: mojoman
6 Replies

8. Shell Programming and Scripting

Log file issue within script

Hi, I have a script where it does several tasks and 3 of them being SQLPLUS activity. Within these SQLPLUS sessions, I have a spool file going but what ever is going on within each SQLPLUS session I would like to write it to my main log file where everything else is running. sqlplus -s <<... (2 Replies)
Discussion started by: ramangill
2 Replies

9. Shell Programming and Scripting

Bash script: issue changing directories in script

I am working on a script that checks two arguments at the command line. The first argument is a search pattern, the second can be a file or a directory, if it is a file a second script is called that checks it for the search pattern. If the second argument is a directory, it checks for the search... (5 Replies)
Discussion started by: Breakology
5 Replies

10. Solaris

Solaris 8 security log issue

Hi all, I'm using Solaris 8 right now. Recently I've a task that needs to log down all unsuccessful login to a log for auditing purpose. What steps do I have to take to log down all login failure logs? Do I've to edit a certain file for it or done by the X-window mode? BTW, do I have to... (2 Replies)
Discussion started by: heero
2 Replies
Login or Register to Ask a Question