Write a script for getout afew line and grep a define word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Write a script for getout afew line and grep a define word
# 1  
Old 08-02-2016
Write a script for getout afew line and grep a define word

dear all
Hi

i want write a script can count number of my log file and every 5min run script for cgk log file for find a specific word such as Error
for example in first 5 min we have 500 line in my log file and in second 5min we have 2500 line in my log file how can chk error word in my log file for every 5 min ?
# 2  
Old 08-02-2016
Welcome Baber,

I have a few to questions pose in response first:-
  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far?
  • Have you got some sample input & desired output?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.


We're all here to learn and getting the relevant information will help us all.
# 3  
Old 08-02-2016
i want use bash script i have wrote this script but not work correctly

Code:
#!/bin/bash
#grep -r 'fetch' /tmp/tt > /tmp/p.txt
#if [ -s "/tmp/p.txt" ]

#c -l < /usr/local/jboss-7.1.1-AMLO/standalone/log/server.log
grep -c "^" /usr/local/jboss-7.1.1-AMLO/standalone/log/server.log > /usr/local/jboss-7.1.1-AMLO/standalone/nglog/x
echo $(( `cat /usr/local/jboss-7.1.1-AMLO/standalone/nglog/x` - `cat /usr/local/jboss-7.1.1-AMLO/standalone/nglog/y`  )) > /usr/local/jboss-7.1.1-AMLO/standalone/nglog/z
cat /usr/local/jboss-7.1.1-AMLO/standalone/nglog/z > /usr/local/jboss-7.1.1-AMLO/standalone/nglog/y
grep -r 'hasan' /usr/local/jboss-7.1.1-AMLO/standalone/log/server.log -n `cat /usr/local/jboss-7.1.1-AMLO/standalone/nglog/z` 

if [ $? = 0 ]

then
echo "OK"
exit 2

else
echo "CRITICAL."
fi

i have create y file with value=0

please help me




Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!

AND: Please answer the other questions as well, esp. the one for homework!

Last edited by RudiC; 08-02-2016 at 09:53 AM.. Reason: Added code tags.
# 4  
Old 08-02-2016
Wow, that's a lot of cating files, and I'm not sure you need all of it. Could you tell us what the plan is? It is much easier to read values, count lines etc. than you are try to do. If you can explain your logic then we might achieve a better bit of code.

So far, I think:-
  • Count lines in x
  • Subtract the value in file y
  • Write the answer back to y
  • Get records from server.log with the string hasan
  • ............ and then it all goes weird with the -n flag and the value from before.
Can you explain a bit better what you need?

It would be good to know the answers to the other questions else I might go off in a way you don't understand and cannot support later.



Thanks,
Robin
# 5  
Old 08-03-2016
Quote:
Originally Posted by rbatte1
Wow, that's a lot of cating files, and I'm not sure you need all of it. Could you tell us what the plan is? It is much easier to read values, count lines etc. than you are try to do. If you can explain your logic then we might achieve a better bit of code.

So far, I think:-
  • Count lines in x
  • Subtract the value in file y
  • Write the answer back to y
  • Get records from server.log with the string hasan
  • ............ and then it all goes weird with the -n flag and the value from before.
Can you explain a bit better what you need?

It would be good to know the answers to the other questions else I might go off in a way you don't understand and cannot support later.



Thanks,
Robin
so thanks

my main plane this is :

1 - i have a log file server that every time it has been changed but now i want every 5 min run script for read a define part of log for example in first time my log file has 500 line and in second 5min log file has 3500 line

in first 5 min i want just chk 500 of first of log file and in second of 5 min want chk next 3000 line now what do i have to do ? i am so confused

Best regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to grep nth word in line?

my input file content is like this GEFITINIB 403 14 -4.786873 -4.786873 -1.990111 0.000000 0.000000 -1.146266 -39.955912 483 VANDETANIB 404 21 -4.754243 -4.754243 -2.554131 -0.090303 0.000000 -0.244210 -41.615502 193 VANDETANIB 405 21 -4.737541 -4.737541 -2.670195 -0.006006 0.000000 -0.285579... (4 Replies)
Discussion started by: chandu87
4 Replies

2. Shell Programming and Scripting

Write a word at 72nd position of a matched line in a file

Hi, I need to search a file for a pattern,replace some other word and write a word at its 72nd position. For example, My name is Mano.Im learning Unix. I want to search the file in all lines containing the word "Mano".In that matched line,replace the word "Unix" with "Java".And... (5 Replies)
Discussion started by: mano1 n
5 Replies

3. Shell Programming and Scripting

awk & grep - check for a value and write sub-word

Hi people, I have a file status.txt: Following 6 ports are totally or partially unavailable: ------------------------------------------------------------ MOD LINK PORTNAMES STAT1 STAT2 STAT3 SYN TYPE ------------------------------------------------------------ 8 Pr37 ... (12 Replies)
Discussion started by: gc_sw
12 Replies

4. UNIX for Dummies Questions & Answers

How to grep word + next line in solaris 10?

Hi my unix friends, How do I grep a word and next line with solaris 10. tnx Mehrdad ---------- Post updated at 03:17 PM ---------- Previous update was at 03:09 PM ---------- I found this one: cat <file_name> | awk '/<seek_word>/ {print;getline;print}' (3 Replies)
Discussion started by: mehrdad68
3 Replies

5. Shell Programming and Scripting

scripting - write a script that will count the number of times a particular word

hello everyone, I'm trying to learn some scripts but i cant get my head around two of them. 1. how can i write a script that will count the number of times a particular word is used in file? 2. how can i make a script that will take me to a web page from unix? if anyone could help it... (3 Replies)
Discussion started by: BigTool4u2
3 Replies

6. Shell Programming and Scripting

grep a word instead of a line

Hi all, I'm a noobie at shell scripting (and Linux) with no experience on programing. I'm trying to create a script that will download my xml calendar from Google, process it in the format and dump it into $HOME/.calendar/calendar. Eg: April 10 Event I'm having a hard time using... (4 Replies)
Discussion started by: victorbrca
4 Replies

7. Shell Programming and Scripting

grep a word from a specific line

for example: searches only for single word for single word this is line three match=$(grep -n -e "single" data.txt) this command will stored "..... single ...... single" into search. how can i grep the single word just from line 2 only?? (3 Replies)
Discussion started by: blurboy
3 Replies

8. UNIX for Dummies Questions & Answers

grep a word from a line

Hi there, Is there a way to grep a word from a line and display only the words beginning from the search word? Say I have a file named file.txt that contains below: I am a file Hello there Reader Orbix I hope you feel good today What I want is to grep the word "there": $ grep "there"... (2 Replies)
Discussion started by: Orbix
2 Replies

9. Shell Programming and Scripting

print a line containing word in a column using grep

hi, how to print a row which contains a perticular word in its third column using grep, cut, or any thing else. thanks (2 Replies)
Discussion started by: useless79
2 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question