# @(#) savelog	6.2		1997-06-04
# Reads from mutvar1 and mutvar2
#
#
#    ========== licence begin  GPL
#    Copyright (c) 2000-2005 SAP AG
#
#    This program is free software; you can redistribute it and/or
#    modify it under the terms of the GNU General Public License
#    as published by the Free Software Foundation; either version 2
#    of the License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#    ========== licence end


use Env;
use Win32;

$HOME = Win32::GetCwd();
$ENV{HOME} = $HOME;

open(FILE_IN, "<./mutvar1") or die "Can't open ./mutvar1"; 
$_ = <FILE_IN>; close FILE_IN;
($DBNAME1, $DB1_SYSUSR, $DB1_SYSPWD, $DB1_CTRL_USR, $DB1_CTRL_PWD) = split / /, $_;

open(FILE_IN, "<./mutvar2") or die "Can't open ./mutvar2"; 
$_ = <FILE_IN>; close FILE_IN;
($DBNAME2, $DB2_SYSUSR, $DB2_SYSPWD, $DB2_CTRL_USR, $DB2_CTRL_PWD) = split / /, $_;

while (1) {

    system("date /T");
    foreach $DB ($DBNAME1, $DBNAME2 ) {
    
		if ( system("x_cons $DB sh sta | grep WARM >nul") ) {
		
			print "save log $DB\n";
			if ( $DB eq $DBNAME1 ) {
			 system("x_diag -u DB1_SYSUSR,DB1_SYSPWD -d $DB -b SAVLOG.cmd");
			}
			else {
			 system("x_diag -u DB2_SYSUSR,DB2_SYSPWD -d $DB -b SAVLOG.cmd");
			}
		}
		else {
			print "don't save log $DB\n";
		}
    }
    sleep 300;
}
