Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
11/07/30 06:13:55 [libopmnoc4j] OC4J ping attempt timed out
11/07/30 06:13:55 [libopmnoc4j] Process Ping Failed: default_group~OC4J_CMG~default_group~1 (1080848993:28956)
I need a script to constantly monitor this log file and look for the above files. if the file is getting any new
messages like above, it has to take the process id from the line
[libopmnoc4j] Process Ping Failed: default_group~OC4J_CMG~default_group~1 (1080848993:28956)
which is 28956 and do kill -9 28956 automatically/immediately.
I need to your expert guidance to achieve the same .
Can you post the code you're running? I can't run the code I posted for you (I don't have either the log file or processes to kill), but this works for me without complaining:
Can you post the code you're running? I can't run the code I posted for you (I don't have either the log file or processes to kill), but this works for me without complaining:
Hm, I just noticed that my /bin/sh is symlinked to bash. Perhaps try running it using "#!/bin/bash" or "#!/usr/bin/bash" (depending where bash is on your system). That's all I can think of, I'm afraid.
As a note: To open a code tag, it's "[ CODE ]" not "[ / CODE ]" (without spaces)
Hm, I just noticed that my /bin/sh is symlinked to bash. Perhaps try running it using "#!/bin/bash" or "#!/usr/bin/bash" (depending where bash is on your system). That's all I can think of, I'm afraid.
As a note: To open a code tag, it's "[ CODE ]" not "[ / CODE ]" (without spaces)
Thanks Snark,
Tried using both "#!/bin/bash" and "#!/usr/bin/bash"
[CODE]
"opmn.sh" 11 lines, 417 characters
#!/usr/bin/bash
while [[ 1 == 1 ]]; do
rev /fraud/appl/orasoa/1013/opmn/logs/opmn.log | grep "$(date +"%y/%m/%d %H:%M:%S").*Process Ping Failed:"
if [ $? ]; then
PID=$(rev /fraud/appl/orasoa/1013/opmn/logs/opmn.log | grep "Process Ping Failed:" | grep -o ":[0-9]*)" | sed 's/://; s/)//')
if kill -9 $PID > /dev/null 2>&1; then
echo "Killed $PID"
fi
fi
sleep 1
done
[CODE]
Am still getting the same error
<frdapps02]orasoa:/fraud/appl/orasoa/1013/opmn/logs> sh opmn.sh
opmn.sh: syntax error at line 4: `PID=$' unexpected
Ah, but you're still calling it with "sh" - try running
Code:
bash opmn.sh
instead.
And nearly there with the code tags - I can't write it in the forum, because it goes funny about it in the forum. If you run:
Code:
printf "\x5BCODE\x5Dyour code in here\x5B/CODE\x5D\n"
then it will print out what it should look like
Sorry to bother you again.. But am getting a different error
<frdapps02]orasoa:/fraud/appl/orasoa/1013/opmn/logs> bash opmn.sh
opmn.sh: line 3: rev: command not found
opmn.sh: line 5: rev: command not found
grep: illegal option -- o
Usage: grep -hblcnsviw pattern file . . .
opmn.sh: line 3: rev: command not found
opmn.sh: line 5: rev: command not found
grep: illegal option -- o
Usage: grep -hblcnsviw pattern file . . .
opmn.sh: line 3: rev: command not found
opmn.sh: line 5: rev: command not found
grep: illegal option -- o
Usage: grep -hblcnsviw pattern file . . .
opmn.sh: line 3: rev: command not found
opmn.sh: line 5: rev: command not found
grep: illegal option -- o
Usage: grep -hblcnsviw pattern file . . .
opmn.sh: line 3: rev: command not found
opmn.sh: line 5: rev: command not found
grep: illegal option -- o
Usage: grep -hblcnsviw pattern file . . .
No need to apologise - I'm the one who's not being very good at giving advice, eh this now comes down to the version of utilities that you have... I use the "util-linux" package (from http://ftp://ftp.kernel.org/pub/linux/utils/util-linux/) which contains 'rev'; certainly there's a "util-linux" package available for Ubuntu and Arch (my distribution of choice), I don't know what distribution you run. For grep:
Code:
$ grep --version
grep (GNU grep) 2.9
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
How does that compare with your version? You could maybe try 'egrep' rather than 'grep', see if your version of that supports the '-o' flag (which prints only the parts of the line which match the pattern, rather than the whole line).
I'd be a little worried that your loop is not going to miss or dupe any instances; depends how fast it loops.
I'd base my soln on 'tail -f' or use the Perl module http://search.cpan.org/~mgrabnar/Fil...0.99.3/Tail.pm
And it's going to keep on going from the end of the file backwards until it finds the latest match - are you just worried that it might spawn two processes which need deleting before it wraps around again? It definitely will hit the same process more than once, but I didn't think this would be an issue as it's already killed the process. However, it did strike me as remarkably inelegant - could you just demonstrate how you could feed 'tail -f' into a loop?
you get the general idea.
The -f switch means follow, so you don't need a loop.
Your orig idea would keep on trying to kill the the same process, leading to extra load on the cpu and spurious error msgs about pid nor found etc, if its quick.
If its slow, it may miss some...
The Perl module gives you a nice clean, controlled soln and you can log more info eg how many killed, how often etc.
BTW, isn't there anyway to cut down/eliminate those failures in the first place ie fix the prob rather than the symptom?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.