- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Unix Script Needed!
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
06-11-2003 10:02 AM
06-11-2003 10:02 AM
I need a UNIX script that someone might have already done or would know how to do with the following requirements:
The script would run every 10 or 15 minutes and look inside a certain application log for the following strings:
2003/06/08 20:08:52 :MGR ,26317:6501 [-07832 Incremental database backup completed successfully.] : Log :
2003/06/08 20:14:13 :MGR ,26317:6501 [-07832 Incremental database backup completed successfully.] : Log :
2003/06/08 20:19:44 :MGR ,26317:6501 [-07832 Incremental database backup completed successfully.] : Log :
I will also attach a sample of the log since the above does not show up on a single line.
The Incremental database backup completed successfully messages show up every 5 or 6 minutes as shown above which indicates that there are no problems.
The script will check the log file for the latest [-07832 Incremental database backup completed successfully.] & compare that time to the current date and time. If no new incremental successful message is in the log within a 10 minute period then it will send an opcmsg (ITO Alert) stating that the incremental backup failed.
I thought a command like this could be used somewhere in the script:
# cat oracle.log-0 | grep "Incremental database backup completed successfully" | tail -1
2003/06/08 20:19:44 :MGR ,26317:6501 [-07832 Incremental database backup completed successfully.] : Log :
Any help someone could provide would be greatly appreciated as I know there are individuals within the forums here who are very good at scripting.
Look forward to hearing from you.
Thanks...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 12:06 PM
06-11-2003 12:06 PM
SolutionYou can keep track of the point from which to read the logfile by storing the last linenumber at which you found a successful backup in a file of its own. When the next 'cron' cycle runs, read that linenumber and begin to search your log from that point forward. If you find a successful event, increment by one, the linenumber found and store that new value and exit, since everything is "OK". If you don't find a successful event logged, trigger your alert logic; leave the "last" linenumber value alone and exit until the next time called.
This script offers a prototype scenario. I used '/etc/hosts' as the "log" and searched for the token "host". Run the script multiple times to see the effect:
#!/usr/bin/sh
typeset MYNAME=${0##*/}
typeset REFF=/tmp/${MYNAME},log
typeset -i LAST
typeset -i CURR
#
if [ -r "${REFF}" ]; then
LAST=`< ${REFF}`
else
LAST=1
fi
#
CURR=`awk -v LAST=${LAST} 'NR>=LAST {if ($0~/host/) {print NR;exit}}' /etc/hosts`
if [ "${CURR}" -eq 0 ]; then
echo "nothing found"
else
echo "isolated @ ${CURR}"
(( LAST=CURR+1 ))
echo "${LAST}" > ${REFF}
fi
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 01:16 PM
06-11-2003 01:16 PM
Re: Unix Script Needed!
#
BEGIN { unshift @INC,"./blib/lib/";}
use File::Tail 0.8;
$name="/yourlogfile.log" unless $name=shift @ARGV;
$debug=shift @ARGV || 0;
$file=File::Tail->new(name=>$name,debug=>$debug,interval=>1,maxinterval=>5,
adjustafter=>20,errmode=>"return") or
die "Could not open $name: $!";
while ($line=$file->read) {
if ( $line =~ /Incremental/ ) {
@message = split/ /, $line;
do something iwht the info...
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 01:18 PM
06-11-2003 01:18 PM
Re: Unix Script Needed!
the previous posting was an extraction of a perl script I wrote to tail a constant growing file and looking for various strings of text.
use it as your starting point, and build from there.
go crayz (download and install File::Tail from http://www.cpan.org)
peace
Donny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2003 12:37 AM
06-12-2003 12:37 AM
Re: Unix Script Needed!
my solution is not a very beautiful one but has been tested successfully on my system... it can certainly be improved.
1. first, create a timestamp file:
# touch /tmp/timestamp
2. the attached script checks whether the last backup ran since the timestamp file was touched. If so, it echoes "OK", if not it echoes "NOK". After having checked, the script touches the timestamp file. Please remember to change the log filename in the script.
You therefore have a script that will check that a backup was correctly completed since the script was last run. Putting the script in the crontab should give you what you're looking for.
HTH,
FiX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2003 01:12 AM
06-12-2003 01:12 AM
Re: Unix Script Needed!
I can't do it easyly in shell, but in C. Compile the simple attached program using make, and it will be called by this script :
#!/usr/bin/sh
simpleprog $(cat oracle.log-0 | grep "Incremental database backup completed successfully"
| tail -1 | tr '/:' ' ' | cut -f1-6) || opcmsg ...
The output if no recent backup is found will be as follow and the exit code will be set so that the opcmsg will be executed :
Last successfull backup was 4 days 1 hours 22 minutes ago
WARNING : no recent successfull backup found !
Else, it will only give you the time of last successfull backup and will exit with 0.
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2003 01:20 AM
06-12-2003 01:20 AM
Re: Unix Script Needed!
if you have already ITO, i suggest you to build the match string in the logfile encaspulator (i remember it is called something like that).
You can write your own match criteria, and this will do your work.
My ITO gurus tell it is feasible, using the ECS and specifygn the correct policy. Maybe a post in the ITO section can be of better help !
HTH,
Massimo