- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script for checking
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2007 01:15 PM
11-27-2007 01:15 PM
Script for checking
1. if there is no "error" word existed in any file , then DO NOT send the mail ;
2. send "error" statement to user one time only , that mean , only inform user the "error" statement one time , if there are same "error" statement within 5 days , send the mail to user one time only ( the user need to know the same error one time only ) . can advise how can I change it ? thx.
FILE=/tmp/error ; export FILE
mailfile=/tmp/mailfile ; export mailfile
find /ora_tmp -type f -mtime -5 -maxdepth 1 | xargs grep -i "error" > $FILE
cat $FILE >> $mailfile
echo $mailfile
mail ora-usr@mydomain.com < $mailfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2007 09:26 PM
11-27-2007 09:26 PM
Re: Script for checking
mv ${FILE}.4 ${FILE}.5
...
mv ${FILE}.0 ${FILE}.1
(To prime the pump, create 5 empty files.)
Then do the find ... grep to ${FILE}.0
After this step, you would remove all lines that were in ${FILE}.1 ... ${FILE}.5
sort -u ${FILE}.[1-5] > ${FILE}.ALL
fgrep -v -f ${FILE}.ALL ${FILE}.0 > $mailfile
rm -f ${FILE}.ALL
(I'm assuming ${FILE}.ALL isn't too big or the performance of the script isn't important.)
Note: There is no need to export FILE and mailfile if you aren't reading them in some other script.
If the same error re-occurs after 5 days, it will be re-sent. If it goes away and then comes back in two days, it won't be re-sent.
1) only send if $mailfile has errors
if [ -s $mailfile ]; then
mailx -s "Error messags" ora-usr@mydomain.com < $mailfile
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2007 07:20 PM
12-10-2007 07:20 PM
Re: Script for checking
I modified the script as below , it can send nodify mail only when there is error ,
but I am not too understand the suggestion above , my requirement is " to send "error" statement to user one time only , that mean , only inform user the "error" statement one time , if there are same "error" statement within 5 days , send the mail to user one time only ( the user need to know the same error one time only ) . can advise ? thx
FILE=/tmp/error ; export FILE
mailfile=/tmp/mailfile ; export mailfile
find /ora_tmp -type f -mtime -5 -maxdepth 1 | xargs grep -i "error" > $FILE
if [ -s $FILE ] ; then
cat $FILE >> $mailfile
echo $mailfile
mail ora-usr@mydomain.com < $mailfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2007 08:26 PM
12-10-2007 08:26 PM
Re: Script for checking
(I assume there is a "fi" to go with the "if".)
>my requirement is "to send error statement to user one time only", that mean, only inform user the "error" statement one time, if there are same "error" statement within 5 days, send the mail to user one time only (the user need to know the same error one time only).
Currently my suggested code sends the error only once, in 5 days. If you want to turn the error back on after 5 days, you would have to fiddle with the 5 error "caches".
Basically, you need more words to describe what you want. I.e. a concrete example.
You could explain what you want for all 2**5 == 32 cases of one error either there or not, for 5 days. :-)
But I don't need that many cases.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2007 05:31 PM
12-24-2007 05:31 PM
Re: Script for checking
what my requirement is find the word "error" in the directory ( I will schedule it to run 3 hour/day ) , if there is "error" within 5 days then send the mail ( includes the file name ) to inform the administrator , BUT only send the same file name to admin one time .
for example , the oracle db generate the error to /tmp time by time , I would like to fix the error once it is happened , but if the error is not fixed yet over 3 hours , then NO NEED to send the same error to administrator , that mean administrator only receive the same error one time . can advise what can i do ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2007 05:58 PM
12-24-2007 05:58 PM
Re: Script for checking
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2007 06:36 PM
12-24-2007 06:36 PM
Re: Script for checking
please ignore the problem .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2007 07:04 PM
12-30-2007 07:04 PM
Re: Script for checking
I would like to state my question again , the oracle is continuely generate some file to /tmp , some of file have error statement in it as below.
$ls /tmp
file1 file2 file3
$vi /tmp/file1
error:the amount is not correct
error:integer problem
$vi /tmp/file2
error:update problem
$vi /tmp/file3
error:exceed no. of input
what I want is to find which files have error in it and send a mail to administrator to inform the error is exist ( the mail have file name and the error statement ) , I will set a crontab job to check it in every 3 hours , but only send the mail one time if the same error, that mean only send a same error to administratior one time , can advise what can i do ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2007 09:37 PM
12-30-2007 09:37 PM
Re: Script for checking
grep -ni error /tmp/file* > ${FILE}.0
# remove errors from before, includes file, line # and message
touch ${FILE}.ERR
fgrep -v -f ${FILE}.ERR ${FILE}.0 > $mailfile
# save new errors
sort -u -o ${FILE}.ERR ${FILE}.ERR ${FILE}.0
rm -f ${FILE}.0
# only send if $mailfile has errors
(copy from above)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2007 09:47 PM
12-30-2007 09:47 PM
Re: Script for checking
One time per check cycle?
One time per file checked?
One time for all files checked?
Anyway, please find below a working skeleton perl solution which surely can readily be adapted to more detailed needs.
Give it a whirl?
[hint: after a first round of testing there will be a 'marker' file. So to re-test you may want to 'touch' a few error files.]
Enjoy,
Hein.
#!/usr/bin/perl
my $DIR = "/tmp/hein";
my $MARK = $DIR."/error_check_marker";
my $OPER = "hein";
use strict;
use warnings;
my $file;
my %errors_seen;
my $last_time = -M $MARK;
$last_time = 9999 unless $last_time;
open (MARK, ">$MARK") or die "Could not touch $MARK";
close MARK; # new modified time stamp
foreach $file (glob $DIR."/*") {
next if $last_time < -M $file; # been there done that?
if (open (FILE, "<$file")) {
$file =~ s/$DIR\///;
while (
chomp;
next unless /^error:/;
if (defined $errors_seen{$'}) {
$errors_seen{$'} .= ",$file";
} else {
$errors_seen{$'} = $file;
}
}
close FILE;
} else {
print STDERR "Could not open $file $!\n";
}
}
if (%errors_seen) {
open (MAIL, "| mailx -s \"Error report\" $OPER") or die "Could not create Email";
printf MAIL "Found the following errors in recent file in $DIR\n";
foreach (sort keys %errors_seen) {
printf MAIL "%25s : %s\n", $_, $errors_seen{$_};
}
close MAIL;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2007 10:03 PM
12-30-2007 10:03 PM
Re: Script for checking
My approach could be augmented by making the 'marker file' retain a list of which errors seen and when.
On startup read the file and discard any marker error older that 5 days. Then only stash those errors in the errors_seen array which were not still in the marker file.
Update the marker fiel from the old data plus the fresh errors.
SMOP!
Hein.