Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a perl script to automate certain processes on our Oracle databases. One portion of the script involves putting the script to sleep until the alert log shows the database open.

I intend to do a sleep until (logevalmodule). The logevalmodule will be a sub procedure that opens and monitors the alert log using tail -f returning a true when the word OPEN appears in the log.

Can anyone help me with possible solutions. I have two hurdles to make this work. The path to the alert log will not be in the same place for all the databases on the Oracle server, for example 'apps13/oracle/admin/db1/bdump' and 'apps14/oracle/admin/db2/bdump'. The other hurdle is to format the tail -f into the script.


share|improve this question
I doubt that you should use tail -f. You should open the file for reading in Perl and seek to the end then just keep reading in a loop and look for "OPEN" using pattern matching. As for the file locations it depends on how complex the variations are, whether they're in constant locations, whether you want to specify them via CL parameter, config file, hardcoded, regex, globbing, etc. – Dennis Williamson Dec 2 '09 at 22:00
thank you. Can i seek the end with LAST? or is there another way? – user27897 Dec 3 '09 at 19:15

In terms of building a Perl module to monitor stuff appearing in Log files I would strongly recommend using Perl Object Environment (POE). I've built a bunch of log monitors using it in the past and it's pretty simple and quite effective. There's a good example showing some tail monitoring\processing of a web server log on the POE Cookbook Site here.

As far as the other part of the problem all I can suggest is set up a bunch of POE Wheels targeting each log you need to monitor, populated in some way that suits you. Personally I'd just read the desired target locations in from a file.

share|improve this answer
I may look into this in the future but I don't really have time to learn about POE. Thanks though. – user27897 Dec 3 '09 at 18:55

Regarding log location:

1) If you have the right privileges on Oracle, you can get the location of the bdump directory by querying v$parameter for "BACKGROUND_ DUMP_DEST".

2) bdump will usually be in $ORACLE_BASE/admin/$ORACLE_SID/bdump The existence of these environment variables is mandatory for user "oracle" or they can be parsed from /etc/oratab

share|improve this answer
Your right and I don't know why I didn't think of that before. This script is on a pool server and is going to loop through each SID, start the database and run some sql scripts. – user27897 Dec 3 '09 at 18:56
is it possible to pipe the result of the sql query into a variable ex. $log_file=(WTR select value from v$parameter where name='background_dump_dest';\n) – user27897 Dec 3 '09 at 19:08
I think so. Something like : $log_directory = ( echo set feed off head off; echo select value from v$parameter where name='background_dump_dest; echo / ;echo quit; ) | sqlplus -s -L / as sysdba – chenshap Dec 3 '09 at 21:26

How about something like:

sub delay_until_open
  my( @log_files) = @_;
  open( ALL_LOGS, 'tail -0f ' . join( ' ', @log_files) . ' |') || die 'oops, it broke';
  while ( <ALL_LOGS>)
    if ( /OPEN/)
  close ALL_LOGS || die 'oops, it broke';

Obviously, the error handling could use some work, but this should scan all of the log files, then end the function when one of them contains (newly appends) OPEN. You won't need a sleep + check loop around this.

In addition, since "tail -f" on multiple files displays the file name when a chunk comes out from one of the files, you could capture the file name in a regex, and return the name of the log file that just announced an "OPEN". Another caveat, doing this as a single process, instead of a 2 step pipeline, means that you may miss some events while you are servicing earlier events.

share|improve this answer
That helps a lot thank you. I am going to try and adapt this to my needs. – user27897 Dec 3 '09 at 19:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.