#!/usr/local/bin/rxx
/* 
   cronrexx args

   sets PATH and REXXPATH appropriately, and then runs program passed as
   arguments.
*/

parse arg program

localpath = "/usr/local/bin"
binpath   = "/u/adsm-mon/bin"

PATH=getenv('PATH')
REXXPATH=getenv('REXXPATH')

/* Add localpath to PATH, if it's not already there. */
pp = PATH
local = 1
do while (pp <> "")
  parse value pp with p ":" pp
  if (p = localpath) then local = 0
  end
if (local) then do
  PATH=localpath':'PATH
  call putenv('PATH='PATH)
  end

/* Add binpath to PATH, if it's not already there. */
pp = PATH
local = 1
do while (pp <> "")
  parse value pp with p ":" pp
  if (p = binpath) then local = 0
  end
if (local) then do
  PATH=binpath':'PATH
  call putenv('PATH='PATH)
  end

/* Add localpath to REXXPATH, if it's not already there. */
pp = REXXPATH
local = 1
do while (pp <> "")
  parse value pp with p ":" pp
  if (p = localpath) then local = 0
  end
if (local) then do
  REXXPATH=localpath':'REXXPATH
  call putenv('REXXPATH='REXXPATH)
  end

/* Add binpath to REXXPATH, if it's not already there. */
pp = REXXPATH
local = 1
do while (pp <> "")
  parse value pp with p ":" pp
  if (p = binpath) then local = 0
  end
if (local) then do
  REXXPATH=binpath':'REXXPATH
  call putenv('REXXPATH='REXXPATH)
  end

/* Diagnostics */
/* say "PATH="getenv('PATH')
say "REXXPATH="getenv('REXXPATH')
*/

/* Run program */
program