/*********************** PALS-IT REXX PROLOGUE *******************************/
/*                                                                           */
/*  Testcase Name:     ITLALERT.CMD                                          */
/*                                                                           */
/*  Descriptive Name:       ALERT GENERATOR                                  */
/*                                                                           */
/*  FUNCTION TESTED:        Alerts due to full disk                          */
/*                                                                           */
/*  TESTCASE OBJECTIVE:                                                      */
/*     DESCRIPTION:                                                          */
/*         Do repetative file copies to fill up the harddisk to a point      */
/*         when the hardisk has less then 15 megs of disk space.  At that    */
/*         time the system erases the test files and starts the process over.*/
/*     END_OF_DESCRIPTION                                                    */
/*                                                                           */
/*     TESTABLE ITEMS:                                                       */
/*         Alert reporting                                                   */
/*                                                                           */
/*  DEPENDENCIES:                                                            */
/*         Currently this exec is written to assume there is at least 15     */
/*         meg available.  Also it is necessary to have LAN Server set up    */
/*         to pop up the alerts (GENALERT must be running).                  */
/*                                                                           */
/*                                                                           */
/*  MANUAL INTERVENTION                                                      */
/*     None                                                                  */
/*                                                                           */
/*     PREREQUISITES:                                                        */
/*                                                                           */
/*                                                                           */
/*     Input Parameters:                                                     */
/*                                                                           */
/*         - None                                                            */
/*                                                                           */
/*     Outputs:                                                              */
/*         - RC= 0 if successful      RC=8 if failed                         */
/*                                                                           */
/*     SPECIAL NOTES:                                                        */
/*                                                                           */
/*         - None.                                                           */
/*                                                                           */
/*  RESTRICTIONS:                                                            */
/*     none                                                                  */
/*                                                                           */
/*  CHANGE ACTIVITY:                                                         */
/*    Ver  Date      NAME         Comments                                   */
/*    1.0  3/04/94  R.Bassemir    Initial release.                           */
/*    1.1  4/05/94  R.Bassemir    Enhanced the exec to check the dir         */
/*    2.0  6/11/97  R.Bassemir    Updates for the PCM selftest kit           */
/*    2.1  6/18/97  R.Bassemir    Corrected a 32 meg loop problem            */
/*                                                                           */
/*        7/03/97  S. Hudson     Change to use OS2DRV instead of hardcode c  */
/*        7/07/97  S. Hudson     Setup to run on S01 - Automated pass/fail   */
/*        7/15/97  S. Hudson     Change to use common functions for methods  */
/*                               of creating history,log files, extracting   */
/*                               local system names, duration times.         */
/*                                                                           */
/*                                                                           */
/*                                                                           */
/******************************-END PROLOGUE-*********************************/
arg loop
TRACE  off

/**************************************************************************/
/* USE OS2 ENVIRONMENT VARIABLE COMSPEC= TO FIND OS/2 BOOT DRIVE.         */
/**************************************************************************/
cmspec = value('COMSPEC',,'OS2ENVIRONMENT');
os2drv = left(cmspec,1)||':'

if loop = "?" then signal help

if loop = "" then loop = 1

loopcnt = 0

/*****************************************************************************/
/*****************************************************************************/
CALL RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
CALL RxFuncAdd 'SysFileSearch','RexxUtil','SysFileSearch'
CALL SysLoadFuncs

/***************** determine NETBIOS name **local system*************/
CALL SysFileSearch 'Computername',os2drv'\ibmlan\ibmlan.ini','file.'
localname = strip(subword(file.1,3,1))

/***************** define the log file and history file *************/
logfile = os2drv'\'||substr(localname,5,3)'logs\itlalert.'||substr(localname,5,3)
histfile = os2drv'\'||substr(localname,5,3)'logs\itlalert.'||substr(localname,5,3)'.history'

/***************** initialize a history file **************************/
res = lineout(histfile, '***** 'time() date()' ITLALERT History *****')
res = lineout(histfile)

/***************** copy existing file to history ********************/
'copy 'histfile'+'logfile' 'histfile
'erase 'logfile

/******* determine the next available DRIVE for a net use ******/
ndrive = nextfree()
if ndrive = 0 then
   do
      say '- There are NO free DRIVES for the NET USE '
      say '           *** This test will end now.'
      exit
   end /* do */

/******* Set GREP Options for checking alert results ***************/
grepchk = '-Ny -r -y'
rcx = value('grepopt',grepchk,'OS2ENVIRONMENT');

/**************** start a new log file *****************************/
res = lineout(logfile, '***** 'time() date()' ITLALERT STARTING *****')
res = lineout(logfile, 'number of requested loops='loop' ')
res = lineout(logfile, 'net use will use drive 'ndrive':')
res = lineout(logfile)


/******* start the building of data files   ***********************/
'cd 'os2drv'\'                               /* start at root directory      */
'md 'os2drv'\itld'                           /*build a directory for testing */
'cd 'os2drv'\itld'                           /* change default directory     */

'erase 'os2drv'\ibmlan\logs\messages.log 2>nul'  /* clear the log now */

res = lineout(logfile, os2drv'\ibmlan\logs\messages.log has been cleared for test')
res = lineout(logfile)

'net use 'ndrive' S01UTIL'                   /* link to disk with data file  */
 IF RC \= 0 then do                          /* exit if the command failed   */
   SAY 'The net use to the additional server failed '
   DATETIME = DATE() TIME()                  /* set time and date            */
   SAY DATETIME                              /* output date and time         */
   res = lineout(logfile, '***** ITLALERT failed to net use to s01util *****'datetime)
   res = lineout(logfile)
   'cd 'os2drv'\'                            /* return to root directory     */
   'zap 'os2drv'\itld'                       /* and remove temp directory    */
   EXIT
 END   /* end the IF RC\=0 statement  */

'copy 'ndrive'\2mb.dat 'os2drv'\itld\2mb.dat'
 IF RC \= 0 then do                           /* exit if the command failed  */
   SAY 'The test needs a 2mb.dat file to start   '
   SAY 'Put a 2mb.dat file in s01util alias and restart'
   DATETIME = DATE() TIME()                   /* set time and date           */
   SAY DATETIME                               /* output date and time        */
   res = lineout(logfile, '***** ITLALERT failed to find a 2Mb.dat file on s01util alias *****'datetime)
   res = lineout(logfile)
   'cd 'os2drv'\'                            /* return to root directory     */
   'zap 'os2drv'\itld'                       /* and remove temp directory    */
   EXIT
 end

res = lineout(logfile, 'Copied 2meg file from additional server successfully ')
res = lineout(logfile)


'dir 'ndrive' > dirspace.inf'                /* put dir info into a file     */
do until lines(dirspace.inf) = 0             /* loop until end of file       */
   freebyte = linein(dirspace.inf)           /* last line is free disk space */
end                                          /* end do until end of file     */
parse value freebyte with var1 var2 var3     /* parse the free bytes         */
xx=lineout(dirspace.inf)                     /* close the file               */
if var1 < 39000000 then call escape          /* test for < 39 megs           */

res = lineout(logfile, 'There are 'var1' bytes left on the drive. Build  4MB file. ')
res = lineout(logfile)


'copy 2mb.dat 4mb.inf'                        /* setup a 4mb test data file  */
 IF RC \= 0 then do                           /* exit if the command failed  */
   SAY 'The copy of the test data file failed. Return code was: ' RC
   DATETIME = DATE() TIME()                   /* set time and date           */
   SAY DATETIME                               /* output date and time        */
   res = lineout(logfile, '***** ITLALERT failed to copy data (2mb file) *****'datetime)
   res = lineout(logfile)
   EXIT
 END   /* end the IF RC\=0 statement  */

'copy 4mb.inf + 2mb.dat'                      /* build a 4mb test data file  */
IF RC \= 0 then do                            /* exit if the command failed  */
   SAY 'The copy of the test data file failed. Return code was: ' RC
   DATETIME = DATE() TIME()                   /* set time and date           */
   SAY DATETIME                               /* output date and time        */
   res = lineout(logfile, '***** ITLALERT failed to copy data (4mb file) *****'datetime)
   res = lineout(logfile)
   EXIT
END    /* end the IF RC\=0 statement  */


'dir 'ndrive' > dirspace.inf'                /* put dir info into a file     */
do until lines(dirspace.inf) = 0             /* loop until end of file       */
   freebyte = linein(dirspace.inf)           /* last line is free disk space */
end                                          /* end do until end of file     */
parse value freebyte with var1 var2 var3     /* parse the free bytes         */
xx=lineout(dirspace.inf)                     /* close the file               */
if var1 < 39000000 then call escape          /* test for < 39 megs           */

res = lineout(logfile, 'There are 'var1' bytes left on the drive. Build  8MB file. ')
res = lineout(logfile)


'copy 4mb.inf 8mb.inf'                        /* setup a 8mb test data file  */
IF RC \= 0 then do                            /* exit if the command failed  */
   SAY 'The copy of the test data file failed. Return code was: ' RC
   DATETIME = DATE() TIME()                   /* set time and date           */
   SAY DATETIME                               /* output date and time        */
   res = lineout(logfile, '***** ITLALERT failed to copy data (4mb file) *****'datetime)
   res = lineout(logfile)
   EXIT
END    /* end the IF RC\=0 statement  */

'copy 8mb.inf + 4mb.inf'                      /* build a 8mb test data file  */
IF RC \= 0 then do                            /* exit if the command failed  */
   SAY 'The copy of the test data file failed. Return code was: ' RC
   DATETIME = DATE() TIME()                   /* set time and date           */
   SAY DATETIME                               /* output date and time        */
   res = lineout(logfile, '***** ITLALERT failed to copy data (8mb file) *****'datetime)
   res = lineout(logfile)
   EXIT
END    /* end the IF RC\=0 statement  */


'dir 'ndrive' > dirspace.inf'                /* put dir info into a file     */
do until lines(dirspace.inf) = 0             /* loop until end of file       */
   freebyte = linein(dirspace.inf)           /* last line is free disk space */
end                                          /* end do until end of file     */
parse value freebyte with var1 var2 var3     /* parse the free bytes        */
xx=lineout(dirspace.inf)                     /* close the file               */
if var1 < 39000000 then call escape          /* test for < 39 megs           */

res = lineout(logfile, 'There are 'var1' bytes left on the drive. Build 16MB file. ')
res = lineout(logfile)


'copy 8mb.inf 16mb.inf'                      /* setup a 16mb test data file  */
IF RC \= 0 then do                           /* exit if the command failed   */
   SAY 'The copy of the test data file failed. Return code was: ' RC
   DATETIME = DATE() TIME()                  /* set time and date            */
   SAY DATETIME                              /* output date and time         */
   res = lineout(logfile, '***** ITLALERT failed to copy data (8mb data) *****'datetime)
   res = lineout(logfile)
   EXIT
END    /* end the IF RC\=0 statement  */

'copy 16mb.inf + 8mb.inf'                    /* build a 16mb test data file  */
IF RC \= 0 then do                           /* exit if the command failed   */
   SAY 'The copy of the test data file failed. Return code was: ' RC
   DATETIME = DATE() TIME()                  /* set time and date            */
   SAY DATETIME                              /* output date and time         */
   res = lineout(logfile, '***** ITLALERT failed to copy data (16mb file) *****'datetime)
   res = lineout(logfile)
   EXIT
END    /* end the IF RC\=0 statement  */


'dir 'ndrive' > dirspace.inf'                /* put dir info into a file     */
do until lines(dirspace.inf) = 0             /* loop until end of file       */
   freebyte = linein(dirspace.inf)           /* last line is free disk space */
end                                          /* end do until end of file     */
parse value freebyte with var1 var2 var3     /* parse the free bytes         */
xx=lineout(dirspace.inf)                     /* close the file               */
if var1 < 39000000 then call escape          /* test for < 39 megs           */

res = lineout(logfile, 'There are 'var1' bytes left on the drive. Build 32MB file. ')
res = lineout(logfile)


'copy 16mb.inf 32mb.inf'                     /* setup a 32mb test data file  */
IF RC \= 0 then do                           /* exit if the command failed   */
   SAY 'The copy of the test data file failed. Return code was: ' RC
   DATETIME = DATE() TIME()                  /* set time and date            */
   SAY DATETIME                              /* output date and time         */
   res = lineout(logfile, '***** ITLALERT failed to copy data (16mb file) *****'datetime)
   res = lineout(logfile)
   EXIT
END    /* end the IF RC\=0 statement  */

'copy 32mb.inf + 16mb.inf'                   /* build a 32mb test data file  */
IF RC \= 0 then do                           /* exit if the command failed   */
   SAY 'The copy of the test data file failed. Return code was: ' RC
   DATETIME = DATE() TIME()                  /* set time and date            */
   SAY DATETIME                              /* output date and time         */
   res = lineout(logfile, '***** ITLALERT failed to copy data (32mb file) *****'datetime)
   res = lineout(logfile)
   EXIT
END    /* end the IF RC\=0 statement  */


'dir 'ndrive' > dirspace.inf'              /* put dir info into a file       */
do until lines(dirspace.inf) = 0           /* loop until end of file         */
   freebyte = linein(dirspace.inf)         /* last line is free disk space   */
end                                        /* end do until end of file       */
parse value freebyte with var1 var2 var3   /* parse the free bytes           */
xx=lineout(dirspace.inf)                   /* close the file                 */
if var1 < 39000000 then call escape        /* test for < 39 megs             */

res = lineout(logfile, 'There are 'var1' bytes left on the drive. Build a bunch of 32 meg files. ')
res = lineout(logfile)


q = 0                                      /* initialize the file counter  */
do until var1 < 39000000                   /* loop until < 39 megs left    */
   'copy 32mb.inf 32mb'||q'.inf'           /* build another 32 meg file    */
   'dir 'ndrive' > dirspace.inf'           /* put dir info into a file     */
   do until lines(dirspace.inf) = 0        /* loop until end of file       */
      freebyte = linein(dirspace.inf)      /* last line is free disk space */
   end                                     /* end do until end of file     */
   parse value freebyte with var1 var2 var3   /* parse the free bytes      */
   xx=lineout(dirspace.inf)                /* close the file               */
   q = q + 1                               /* increment the file counter   */
   res = lineout(logfile, 'A 32 meg file was built (number 'q')')
   res = lineout(logfile)
end                                        /* end do until < 39 meg loop   */

call escape


escape:                  /* routine to get disk space from < 39 to below 15m */
y = 0                                      /* initialize the file counter    */
res = lineout(logfile, 'Just 'var1' bytes left on the drive.  Build 4MB files to get below 15MB. ')
res = lineout(logfile)


do until var1 < 15000000                   /* loop until < 15 megs left    */
   'copy  4mb.inf  4mb'||y'.inf'           /* build another 4 meg file     */
   'dir 'ndrive' > dirspace.inf'           /* put dir info into a file     */
   do until lines(dirspace.inf) = 0        /* loop until end of file       */
      freebyte = linein(dirspace.inf)      /* last line is free disk space */
   end                                     /* end do until end of file     */
   parse value freebyte with var1 var2 var3  /* parse the free bytes       */
   xx=lineout(dirspace.inf)                /* close the file               */
   y = y + 1                               /* increment the file counter   */
   res = lineout(logfile, 'A 4 meg file was built (number 'y')')
   res = lineout(logfile)
end                                        /* end do until < 15 meg loop   */


res = lineout(logfile, 'Just 'var1' bytes left, wait for the alert')
res = lineout(logfile)

say 'Look for the alert popup indicating disk is almost full'
say 'Can check the Network Messaging window if you miss the popup'

loopcnt = loopcnt + 1

Say'ITLALERT has looped 'loopcnt' times.'
SAY'...Sleeping for 2 minutes before continuing'

call SysSleep 120

res = lineout(logfile, '***********************************************************')
res = lineout(logfile)
'type 'os2drv'\ibmlan\logs\messages.log >>'logfile
res = lineout(logfile, '***********************************************************')
res = lineout(logfile)

'erase 'os2drv'\itld\*.inf'                /* erase all data files           */
'erase 'os2drv'\itld\2mb.dat'              /* erase last data file           */
'cd 'os2drv'\'                             /* return to root directory       */
'zap 'os2drv'\itld'                        /* remove temp directory          */

'grep "Drive 'os2drv' is nearly full"  'logfile' >nul'
if rc = 1 then do
   /****** run completed successfully, log the pass *******************/
   res = lineout(logfile, '***** 'time() date()' ITLALERT Completed successfully *****')
   res = lineout(logfile)
   end
else do
   /****** did not find alert message, log the fail *******************/
   res = lineout(logfile, '***** 'time() date()' ITLALERT Completed successfully *****')
   res = lineout(logfile)
   end

EXIT

HELP:
say ' This test will build a temp directory and fill it up with data'
say ' files until there is less then 15 megs of data left  on the hard drive'
say ' The syntax is: '
say ' '
say ' ITLALERT  loop'
say ' '
say ' Where loop is the number of times you want this test to repeat'
say ' The default is one.'
exit
