Thursday, January 24, 2008

FW: sample scripts

#!/bin/ksh
##################################################################
# ETL Name: mol_reo_auto_valutn_cfcnt_hst.shl
#
# Description: Shell to Load CDW table mol_reo_auto_valutn_cfcnt_hst
# Date: 05/30/2007
# Author: Nitin Gulati (c14900)
# Change:
##################################################################

CDWInfo()
{
echo "#INFO:`${CURR_TS}`:${1}"
}

CDWWarn()
{
echo "#WARNING:`${CURR_TS}`:${1}"
}

CDWErr()
{
echo "#ERROR:`${CURR_TS}`:${1}"
}

#-----------------------------------------------------------------
# LOCAL VARIABLE SECTION
#-----------------------------------------------------------------
SET_VAR()
{
CDWInfo "SET_VAR() Started ........"

export DB2INSTANCE=${DB2PROF}

export CDWDIR=/fmac/${ENV}/mis/cdw
export DATADIR=/fmacdata/${ENV}/mis/cdw
export CNTLDIR=${CDWDIR}/cntl
export BINDIR=${CDWDIR}/util/bin
export SHLDIR=${CDWDIR}/shl
export SRCDIR=${CDWDIR}/src
export DATA_IN=${DATADIR}/datain
export DATA_OUT=${DATADIR}/dataout
export LOGDIR=${DATADIR}/logs
export TRGR_DIR=${DATADIR}/trigger
export CNTL_RPT_FILE=${DATA_OUT}/${TABLE_NAME}_cntl_report.csv
export SRC_FILE_NAME=cl_autovl_coeff_hst
export DATA_FILE=${DATA_IN}/${SRC _FILE_NAME}.csv
export MAIL_CDW_SUPPORT=${CNTLDIR}/CDW_support_mail_list.txt
export MAIL_RPT_FILE=${CNTLDIR}/${SRC_FILE_NAME}_support_mail_list.txt

CDWInfo "SET_VAR() Ended ........"
}

#------------------------------------------------------------------------------
# This Function Set the LOG file for that day and append if exists
#------------------------------------------------------------------------------
SET_LOG_FILE()
{
CDWInfo "SET_LOG_FILE() Started ........"

export LOGFILE=${LOGDIR}/${PROG}_${EXT}.log
exec 3>> $LOGFILE

if [ $? -ne 0 ]
then
CDWErr "CANNOT write/create log file:${LOGFILE}"
CDWErr "SET_LOG_FILE() Terminated ........"
exit 9
else
CDWInfo "$PROG Started ..... " >&3 2>&3
CDWInfo "Setting Environment to:${ENV} and Data Base to:${DB2DBDFT}" >&3 2>&3
fi

CDWInfo "SET_LOG_FILE() Ended ........"
CDWInfo "SET_LOG_FILE() Ended ........" >&3 2>&3
}

#------------------------------------------------------------------------------
# This Function Send e-mail in this program fail
#----------------------------------------------------------- -------------------

SEND_MAIL()
{
FILE_TO_MAIL=$1
MAIL_FILE_NAME=$2

if [ -f ${MAIL_FILE_NAME} ]
then
MAIL_LIST=`cat ${MAIL_FILE_NAME} `
else
MAIL_LIST="nitin_gulati@freddiemac.com,apurva_patel@freddiemac.com"
fi

cat ${FILE_TO_MAIL} |mail -s "${MAIL_MSG}" ${MAIL_LIST}
}

#------------------------------------------------------------------------------
# This Function will clean 10 days or older log and outfile for LOB & DATA_TYPE
#------------------------------------------------------------------------------
CLEAN_UP_LOG()
{
MOVE_AND_COMPRERSS ${DATA_FILE}
MOVE_AND_COMPRERSS ${DATA_FILE}.txt

CDWInfo "CLEAN_UP_LOG Started ..." >&3 2>&3

## Clean-up of old log file -main programe
for FILE in `find ${LOGDIR} -name ${PROG}.*.log -mtime +30 `
do
rm -f ${FILE} && printf "removed: %s for being more than 10 days(s) old.\n" $FILE | tee -a ${LOGFILE}
done

## Clean-up of Old Source/CDW date file
for FILE in `find ${DATA_IN} -name ${SRC_FILE_NAME}*.*.*.Z -mtime +160 `
do
rm -f ${FILE} && printf "removed: %s for being more than 160 days(s) old.\n" $FILE | tee -a ${LOGFILE}
done

## Clean-up of Old Control Report file
for FILE in `find ${DATA_OUT} -name ${CNTL_RPT_FILE}_*.csv -mtime +60 `
do
rm -f ${FILE} && printf "removed: %s for being more than 40 days(s) old.\n" $FILE | tee -a ${LOGFILE}
done

CDWInfo "CLEAN_UP_LOG Ended ..." >&3 2>&3
}

#------------------------------------------------------------------------------
# This Function will move and compress PS and CDW Data Files
#------------------------------------------------------------------------------
MOVE_AND_COMPRERSS()
{
export FILE_NAME=$1

CDWInfo "Move and compress started for ${FILE_NAME}" >&3 2>&3


if [ -f ${FILE_NAME} ]
then
chmod 644 ${FILE_NAME}

mv -f ${FILE_NAME} ${FILE_NAME}.${EXT}

if [ $? -eq 0 ]
then
compress -f ${FILE_NAME}.${EXT}
else
CDWWarn "${PROG}:compress Failed for: ${FILE_NAME}" >&3 2>&3
fi
else
CDWWarn "File: ${FILE_NAME} NOT FOUND " >&3 2>&3
fi

CDWInfo "Move and compress ended for ${FILE_NAME}" >&3 2>&3
}

#------------------------------------------------------------------------------
# This Function prepare list of Available files
#------------------------------------------------------------------------------
PREP_LOAD_RDY_FILE()
{
integer in_rec_cnt

if [ -f ${DATA_FILE} ]
then
in_rec_cnt=`cat ${DATA_FILE} | wc -l`
else
CDWWarn "Cannot find input file:${DATA_FILE}" >&3 2>&3
exit 0
fi

if [ ${in_rec_cnt} -le 0 ]
then
CDWInfo "No Detail record found in input data file:${DATA_FILE}" >&3 2>&3
exit 0
else
cat ${DATA_FILE} | grep -c '^FTR' | read NO_OF_FTR_REC

if [ ${NO_OF_FTR_REC} -ne 1 ]
then
CDWErr "Footer record is missing or More then one footer record " >&3 2>&3
MAIL_MSG="${ENV}:Footer record is missing or More then one footer record "
SEND_MAIL ${LOGFILE} ${MAIL_CDW_SUPPORT}
exit 9
else
IFS=,
cat ${DATA_FILE} | grep '^FTR'| sed -e 's/ //g' | cut -d, -f 2-5 | read DT_AUTO_VALUTN_CFCNT_CREATN DT_AUTO_VALUTN_CFCNT_APPRL TOTAL_OF_HASH_COEFF NO_OF_DATA_ROWS

unset IFS

echo "DT_AUTO_VALUTN_CFCNT_CREATN:${DT_AUTO_VALUTN_CFCNT_CREATN} "
echo "DT_AUTO_VALUTN_CFCNT_APPRL:${DT_AUTO_VALUTN_CFCNT_APPRL} "
echo "TOTAL_OF_HASH_COEFF:${TOTAL_OF_HASH_COEFF} "
echo "NO_OF_DATA_ROWS:${NO_OF_DATA_ROWS} "
fi

fi

grep -v '^FTR' ${DATA_FILE} > ${DATA_FILE}.txt

if [ $? -ne 0 ]
then
CDWErr "Failed to Create File:${DATA_FILE}.txt from ${DATA_FILE}.txt" >&3 2>&3
MAIL_MSG="${ENV}:Failed to Create File:${DATA_FILE}.txt from ${DATA_FILE}.txt"
SEND_MAIL ${LOGFILE} ${MAIL_CDW_SUPPORT}
exit 9
else
integer CDW_REC_CNT=`cat ${DATA_FILE}.txt | wc -l `

IFS=,
integer NO_OF_DT_EFF=`cat ${DATA_FILE}.txt | cut -d, -f 1 | sort -u | wc -l`
unset IFS

if [ ${NO_OF_DT_EFF} -eq 1 ]
then
IFS=,
head -1 ${DATA_FILE}.txt | cut -d, -f 1 | read DT_AUTO_VALUTN_CFCNT_EFF
unset IFS
else
CDWErr "${ENV}: More then one DT_AUTO_VALUTN_CFCNT_EFF Found from ${DATA_FILE}" >&3 2>&3
MAIL_MSG="${ENV}:More then one DT_AUTO_VALUTN_CFCNT_EFF Found from ${DATA_FILE}"
SEND_MAIL ${LOGFILE} ${MAIL_CDW_SUPPORT}
exit 9
fi
fi

if [ ${CDW_REC_CNT} -ne ${NO_OF_DATA_ROWS} ]
then
CDWErr "Record Count Between File:${DATA_FILE}.txt(${CDW _REC_CNT}) and Footer(${NO_OF_REC_FTR}) didnot match" >&3 2>&3
MAIL_MSG="${ENV}:Record Count Between File:${DATA_FILE}.txt(${CDW_REC_CNT}) and Footer(${NO_OF_REC_FTR}) didnot match"
SEND_MAIL ${LOGFILE} ${MAIL_CDW_SUPPORT}
exit 9
else
RUN_DS_JOB
GEN_CNTL_RPT
fi
}

#------------------------------------------------------------------------------
# This Function Control Report
#-----------------------------------------------------------------------------
CNTL_REPT_AMT()
{
export NET_COEFF_AMT
NET_COEFF_AMT=`echo "${TOTAL_OF_HASH_COEFF}-(${TOTAL_OF_COEFF})" | bc `
echo "Total Sum of Coeff:,${TOTAL_OF_HASH_COEFF},${TOTAL_OF_COEFF},${NET_COEFF_AMT}\c" >> ${CNTL_RPT_FILE}
if [ ${NET_COEFF_AMT} == 0 ]
then
echo "${RECON}" >> ${CNTL_RPT_FILE}
echo " Sum of Hash Coeff calculated from table ${TABLE_NAME} matches with the Footer Coeff total " >&3 2>&3
else
echo "${NOT_RECON}" >> ${CNTL_RPT_FILE}
echo " There is a mismatch between Sum of HasH Coeff calculated from table ${TABLE_NAME} and the Footer Coeff Total" >&3 2>&3
fi
}

#-----------------------------------------------------------------------------
# Control Report for Record Count
#----------------------------------------------------------------------------
CNTL_REPT_CNT()
{
export NET_REC_COUNT
NET_REC_COUNT=`expr ${NO_OF_DATA_ROWS} - ${RowCount}`
echo "Number of Record Count:,${NO_OF_DATA_ROWS},${RowCount},${NET_REC_COUNT}\c" >> ${CNTL_RPT_FILE}
if [ ${NET_REC_COUNT} == 0 ]
then
echo "${RECON}" >> ${CNTL_RPT_FILE}
echo " Total number of rows from table ${TABLE_NAME} matches with the Footer total count " >&3 2>&3
else
echo "${NOT_RECON}" >> ${CNTL_RPT_FILE}
echo " There is a mismatch between number of rows in table ${TABLE_NAME} and the Footer total count" >&3 2>&3
fi
}
#---------------------------------------------------------------------------
# Send Control Report
#--------------------------------------------------------------------------
SEND_REPT()
{
if ( [ ${NET_COEFF_AMT} -eq 0 ] && [ ${NET_REC_COUNT} -eq 0 ] )
then
export STATUS=PASS

else
export STATUS=FAILED
fi

export MAIL_MSG="REO Valution Coeff Control Report --> ${STATUS}"

SEND_MAIL ${CNTL_RPT_FILE} ${MAIL_RPT_FILE}
}
#------------------------------------------------------------------------------
# This Function Run Data Stage Job
#------------------------------------------------------------------------------
RUN_DS_JOB()
{
CDWInfo "Running DataStage Job:${DS_JOB_NAME} on DS Project:${DS_INST}" >&3 2>&3

export DS_JOB_NAME=pxLdMolReoValCfcntHst

dsjob -param DATA_IN=${DATA_FILE}.txt -param DT_AUTO_VALUTN_CFCNT_APPRL=${DT_AUTO_VALUTN_CFCNT_APPRL} -param DT_AUTO_VALUTN_CFCNT_CREATN=${DT_AUTO_VALUTN_CFCNT_CREATN} ${DS_INST} ${DS_JOB_NAME} > /dev/null

Ret_Code=$?

if ( [ ${Ret_Code} -eq 0 ] || [ ${Ret_Code} -eq 4 ] )
then
CDWInfo "Load Job:${DS_JOB_NAME} completed for Data File:${DATA_FILE}.txt with Return Code:${Ret_Code} on DS_PROJ:${DS_INST}" >&3 2>&3
else
CDWWarn "${DS_JOB_NAME} FAILED for Data File:${DATA_FILE}.txt with Return Code:${Ret_Code} on DS_PROJ:${DS_INST}" >&3 2>&3
exit 9
fi
}

GEN_CNTL_RPT()
{
CDWInfo "Setting Control Report File to:${CNTL_RPT_FILE}" >&3 2>&3

if [ -f ${CNTL_RPT_FILE} ]
then
rm -f ${CNTL_RPT_FILE}
fi

echo "REO Valutions Coeff Control Report,,,Run Date: `date`" > ${CNTL_RPT_FILE}

if [ $? -ne 0 ]
then
CDWErr "Failed to create Control Report File:${CNTL_RPT_FILE} " >&3 2>&3
MAIL_MSG="${ENV}:Failed to create Control Report File:${CNTL_RPT_FILE}"
SEND_MAIL ${LOGFILE} ${MAIL_CDW_SUPPORT}
exit 9
fi

echo "REO Valutions Coeff Control Summary Report" >> ${CNTL_RPT_FILE}
echo >> ${CNTL_RPT_FILE}
echo "Control Item:,CLAS,CDW,Difference,Comments" >> ${CNTL_RPT_FILE}


${DB2_BIN}/db2 -x "select sum(val_auto_valutn_cfcnt), count(*) from udbadm.${TABLE_NAME} where DT_AUTO_VALUTN_CFCNT_EFF = '${DT_AUTO_VALUTN_CFCNT_EFF}' and date(dt_srce_end) = '9999-01-01-00.00.00.000000' and flag_del = 'N' " | read TOTAL_OF_COEFF RowCount

if [ $? -ne 0 ]
then
CDWErr "Failed to retrive data from udbadm.${TABLE_NAME}" >&3 2>&3
MAIL_MSG="${ENV}:Failed to retrive data from udbadm.${TABLE_NAME}"
SEND_MAIL ${LOGFILE} ${MAIL_CDW_SUPPORT}
exit 9
else
CNTL_REPT_AMT
CNTL_REPT_CNT
SEND_REPT
fi
}

#########################################################################################
#
# MAIN
#
#########################################################################################
export NOT_RECON=",NOT-Reconciled"
export RECON=",Reconciled"

export PROG=`basename $0`
export CURR_TS="date +"%Y-%m-%d-%H.%M.%S""
export EXT=`date +"%Y%m%d"`
export EXT_LONG=`date +"%Y-%m-%d-%H.%M.%S"`
echo "#BEGIN:`$CURR_TS` :$PROG Started .... "

. /fmac/users/cdwmgr/.profile

. /fmac/users/cdwmgr/.setServer

if [ $? -ne 0 ]
then
CDWErr "/fmac/users/cdwmgr/.setServer Failed ........"
exit 9
else
. /fmac/users/cdwmgr/.setPXEnvironment

if [ $? -ne 0 ]
then
CDWErr "/fmac/users/cdwmgr/.setPXEnvironment Failed ........"
exit 9
fi
fi

. /fmac/${ENV}/mis/cdw/CDWprofile
. /udb/home/$DB2PROF/sqllib/db2profile
export DB2_BIN=/udb/home/${DB2INSTANCE}/sqllib/bin

trap 'trapfunc' INT QUIT TERM

function usageerr
{
echo "\n\nUSAGE: ${PROG} [ -d {CDWD/CDWU/CDWP/CDWPBCP} ] [ -p {CDW_DEV/CDW_PROD} "
echo
echo "Example ${PROG} -d CDWD -p CDW_DEV \n\n"
exit 2
}

function trapfunc
{
CDWErr "${PROG}: Signal caught. Exiting with code: $RC" | tee -a $LOGFILE
exit 255
}

while getopts :d:p:h arguments
do
case ${arguments} in
d) TRGT_DB=${OPTARG};;
p) DS_INST=${OPTARG};;
h) usageerr;;
:) print "$PROG: $OPTARG requires a value."
usageerr;;
?) print "$PROG: Invalid option: $OPTARG"
usageerr;;
esac
done

shift OPTIND-1

export TABLE_NAME=mol_reo_auto_valutn_cfcnt_hst

SET_VAR
SET_LOG_FILE


if [ ${TRGT_DB} ]
then
export DB2DBDFT=`echo ${TRGT_DB} | tr "[a-z]" "[A-Z]"`
fi


if [ ${DS_INST} ]
then
CDWInfo "Setting Data Stage Project to:${DS_INST}" >&3 2>&3
else
if [ ${ENV} = "dev" ]
then
DS_INST=CDW_DEV
else
DS_INST=CDW_PROD
fi

CDWInfo "Setting Default Data Stage Project to:${DS_INST}" >&3 2>&3
fi

export DB2INSTANCE=${DB2PROF}
PREP_LOAD_RDY_FILE

 

 

-----Original Message-----
From: Yadlapati Srikanth
Sent:
Tuesday, December 11, 2007 11:28 AM
To: Vanamamalai Murali
Subject: FW: sample scripts

 

 

 

-----Original Message-----
From: Yadlapati Srikanth
Sent:
Wednesday, December 05, 2007 3:54 PM
To: 'jasingh2@in.ibm.com'
Subject: sample scripts

 

Sample datastage script

**********************************************************************

CONFIDENTIALITY: This communication, including attachments, is for the exclusive use of the

addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended

recipient, any use, copying, disclosure, or distribution or the taking of any action in reliance upon this

information is strictly prohibited. If you are not the intended recipient, please notify the sender

immediately and delete this communication and destroy all copies.

**********************************************************************

 

FW: files

Controls:
========
1) Adequate set of controls for loading data from Financials to EPM
- At all levels
- Automation
- Quality
- Integrity
- What processes
balances/row counts
- Error handling - sending emails
- Creating schedule (sequential, parallel) - Atleast once a day with flexibility to run adhoc

2) Current Status of Stress testing
- Driving refresh rate
- How long does it take to refresh the data

3) EPM scenarios
- What are the complete scenarios


High level plan
===============
1) I have not seen it

Dependecies
============
3 and 3b and 6 can run in parallel
4 and 5 are dependent on 3
5 is dependent on 4


Hash file location/what to look for in the hash file
balance/row counts and table names by job grouping
Error handling - Dsjob exit status/row counts/balances


Donot run AP&GL
===============
Use Batch00
XLEBICCC
BBBATCH
VNDCNV

 

 

-----Original Message-----
From: Yadlapati Srikanth
Sent:
Tuesday, December 11, 2007 11:27 AM
To: Vanamamalai Murali
Subject: FW: files

 

Hash file location

The hash file is located in the directory:

 

/apps/Ascential/DataStage/Projects/<db name>/SDKMaxLastUpdDttm_E

 

In order to read it we must use the dssh executable.  The command looks like this:

$DSHOME/bin/dssh "SELECT MaxDateTime from SDKMaxLastUpdDttm_E where JobName=<DS_SERVER_JOB>;"

 

In order for this to work you must be in the DataStage Projects folder associated with the given database instance.

 

 

-----Original Message-----
From: Srikanth Yadlapati [mailto:srikanth.yadlapati@us.ibm.com]
Sent:
Tuesday, December 11, 2007 11:16 AM
To: Yadlapati Srikanth
Subject: files

 

(See attached file: EPM batch jobs info.txt)

Srikanth Yadlapati
I/T Architect
Application Innovation Services, IBM IGS
Cell: 678-773-4210
Tie Line: 546-987
srikanth.yadlapati@us.ibm.com

**********************************************************************

CONFIDENTIALITY: This communication, including attachments, is for the exclusive use of the

addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended

recipient, any use, copying, disclosure, or distribution or the taking of any action in reliance upon this

information is strictly prohibited. If you are not the intended recipient, please notify the sender

immediately and delete this communication and destroy all copies.

**********************************************************************

 

RESET OPR PASSWORD

UPDATE PSOPRDEFN

SET OPERPSWD = (SELECT OPERPSWD FROM PSOPRDEFN WHERE OPRID='STPBATCH')

WHERE OPRID IN ('PUPASANI','UBHATTAR','JSINGH');

 

/2dLK39YXHf+Zs/UlQhbqZkKxnY= (XL_2454481)

 

UPDATE

--SELECT OPRID FROM

PSOPRDEFN

SET ACCTLOCK = '1'

WHERE OPRID NOT IN  ('UBHATTAR', 'JSINGH', 'MAHLU', 'PUPASANI', 'RCHUA', 'STPBATCH', 'SSUTEXT01', 'BATCH00', 'FORGOTPSWD', 'PTWEBSERVER', 'STARTAPP', ' XLINFRA')

/

 

 

 

 

Browse the App Server Filesystem via iScript

Print

E-mail

 

Tuesday, 02 January 2007

Debugging that SQL-intensive page is easier when you can get to your trace files quickly. And sometimes it's easier to look in the Process Scheduler config file to see where it's pulling SQR's from than to ask your over-worked DBA. But the reality is that you don't always have access to the servers filesystems to pull this valuable information. Well no worries, here's a technique to browse your Application Server's filesystem using nothing but a little PeopleCode.

It's actually pretty easy to write a set of PeopleCode functions to display a directory structure and view a file. The functions you'll need are all well documented in PeopleBooks, with sample code and everything. If you combine them into an iScript with a few parameters on the query line, you can create a nice application server browsing utility.

Here's a screen shot:
Browse Files Screenshot

It works pretty much like you'd expect. By default it will start in the LOGS directory ($PS_HOME/appserv/<domain>/LOGS). Clicking ".." takes you up one directory, clicking on a directory takes you into that directory, and clicking a file attempts to display it in the browser window. It doesn't do any checking for file content before it sends it to your browser, so be careful what file you click on!
Here's the code that I used:

/******** This iScript lists and views files in a directory ********/
Function IScript_ListDirectory()
 
&Domain = "PS89FNSB";
%Response.WriteLine("<p align=""center""><b>" | "Directory Listing" | "</b></p>");
&PS_HOME = GetEnv("PS_HOME");
 
Local string &pwd;
&pwd = %Request.GetParameter("curdir");
If None(&pwd) Then
&pwd = &PS_HOME | "/appserv/" | &Domain;
End-If;
 
If Right(&pwd, 2) = ".." Then
&pwd = Left(&pwd, Len(&pwd) - 3);
For &i = Len(&pwd) To 1 Step - 1
If Right(&pwd, 1) <> "/" Then
&pwd = Left(&pwd, Len(&pwd) - 1);
Else
&pwd = Left(&pwd, Len(&pwd) - 1);
&i = 0;
End-If;
End-For;
%Response.RedirectURL(EncodeURL(%Request.ContentURI | "/EMPLOYEE/EMPL/s/WEBLIB_BM_XX.USER1.FieldFormula.IScript_ListDirectory?&disconnect=y&type=public&curdir=" | &pwd));
End-If;
 
Local array of string &FNAMES;
Local File &MYFILE;
Local string &CurrFile;
 
&FNAMES = FindFiles(&pwd | "/*", %FilePath_Absolute);
If &FNAMES.Len = 0 Then /* No files in this directory - this must be a file instead */
%Response.RedirectURL(EncodeURL(%Request.ContentURI | "/EMPLOYEE/EMPL/s/WEBLIB_BM_XX.USER1.FieldFormula.IScript_ViewFile?&disconnect=y&type=public&Filename=" | &pwd));
Else
%Response.WriteLine("Directory: " | &pwd | "<br><br>");
While &FNAMES.Len > 0
&CurrFile = &FNAMES.Shift();
rem &FileURL = %Request.ContentURI | "/EMPLOYEE/EMPL/s/WEBLIB_BM_XX.USER1.FieldFormula.IScript_ViewFile?&disconnect=y&type=public&Filename=" | &CurrFile;
&FileURL = %Request.ContentURI | "/EMPLOYEE/EMPL/s/WEBLIB_BM_XX.USER1.FieldFormula.IScript_ListDirectory?&disconnect=y&type=public&curdir=" | &CurrFile;
%Response.WriteLine("<a href=""" | &FileURL | """> " | Substring(&CurrFile, Len(&pwd) + 2, Len(&CurrFile) - Len(&pwd) + 2) | "</a></br>");
End-While;
End-If;
End-Function;
 
Function IScript_ViewFile()
&Filename = %Request.GetParameter("FILENAME");
 
Local File &ServerFile;
Local string &ln, &RelativePath;
 
%Response.Write("<p align=""center""><b>" | &Filename | "</b></p>");
 
 
/* Note: To restrict access to a particular directory or subdirectory, set the environment
variable PS_FILEDIR on your application server to point to that directory. Otherwise
the user will be restricted to the PS_SERVDIR environment variable.
 
To disable security altogether, comment out the relitive path logic and replace %FilePath_Relative in the GetFile method to %FilePath_Absolute
*/
 
rem Get the relative path name;
 
If GetEnv("PS_FILEDIR") <> "" Then
&RelativePath = GetEnv("PS_FILEDIR");
Else
&RelativePath = GetEnv("PS_SERVDIR") | "/files";
End-If;
 
If Left(&Filename, Len(&RelativePath)) = &RelativePath Then
&Filename = Right(&Filename, Len(&Filename) - Len(&RelativePath));
End-If;
 
 
rem Open the file;
&ServerFile = GetFile(&Filename, "R", "A", %FilePath_Relative);
%Response.Write("<p>");
While &ServerFile.ReadLine(&ln);
%Response.WriteLine(&ln | "<br>");
End-While;
%Response.WriteLine("</p>");
&ServerFile.Close();
 
End-Function;

There are two basic functions: IScript_ListDirectory() and IScript_ViewFile.

The ListDirectory function first sets some basic values. You'll want to change the "DOMAIN" value to be your application server domain, so that it will be able to change to the default directory correctly. (You can get the domain from a CTRL-J in your browser). Then it takes the directory passed in the "curdir" query parameter (or the default directory) and sends them to the browser as a hyperlink back to this same ListDirectory function. If for some reason the first entry isn't a ".", this isn't a directory so it must be a file and it redirects you to the ViewFile iScript with the filename passed as a query parameter.

The ViewFile function uses the GetFile function to open the file passed on the URL in the Filename query parameter. It uses the %FilePath_Relative option to keep users from opening files above the directory you specify in the PS_FILEDIR or PS_SERVDIR environment variables to keep things somewhat secure. If security isn't an issue in your environment, you can follow the instructions in the comment to disable security.

Once the file is open, the function reads it one line at a time and sends it to your browser, adding a <br> tag at the end of each line.

Security Warning

This code opens up some security issues. While you can restrict users to a top-level directory for viewing the contents of files, users can browse the directory structure of the entire system with the authority of the Application Server user ID.

As a result, use some common sense before deploying this code. Make sure your systems administrator and management approves. Be sure that your app server user doesn't have access to view directories that you don't want them to view. Use the PS_FILEDIR environment variable to lock users down to a specific directory.

Making it work
Here's how to put the code into a web library, set security, and hit it with a URL:

 

1.    First, create a new derived work record that starts with WEBLIB, like WEBLIB_XX.

2.    Insert a new field into the record. ISCRIPT1 works.

3.    On the FieldFormula PeopleCode, insert the code from earlier in this post.

4.    Now go on-line and pull up your favorite permission list that is in your profile. Go to the Web Libraries tab and insert a row. Pick the WEBLIB created in step 1, click Edit, and click the Full Access All button. Then click OK and Save.

5.    Now you can access the iScript with this URL (Just replace the bold parts with values that make sense in your environment):
http://<server>.<domain>:<port>/psc/<website>/EMPLOYEE/EMPL/s/WEBLIB_XX.ISCRIPT1.FieldFormula.IScript_ListDirectory? disconnect=y&type=public&curdir=/usr/local/psoft/FDMO89/appserv/FDMO89/LOGS

6.    The first time you click on the URL, it may ask you for a PS username/pwd. Go ahead and log on. It may tell you you're not authorized. Just paste the same URL in your browser again and it should show you the directory listing.

Comments (2)add

feed

... : Brent Martin

There's been some discussion about this on the Yahoo PeopleSoft Fans user group (http://groups.yahoo.com/group/peoplesoft-fans). Bruce found that I should have used EncodeURL on my redirects which I've corrected in this post. He also left this comment which has a couple of good points you'll want to consider:

Hi Brent,

A couple of other things I did, taking your security warning to heart, included removing the ability to navigate out of the LOG directory and only showing files with LOG in the name in the file list.


I also added a portal navigation for this iscript rather than pasting in the URL. I passed in the parameter for curdir, under the iscript parameters, which in our case is /PT846/appserv/HC89/LOGS/. I had to use the Unix style slash for this since the Windows style, , wasn't recognized and the navigation failed as it saw curdir=PT846appservHC89LOGS. It took a while to figure that one out.

regards,
Bruce

January 11, 2007

Binary files : Joe : http://xtrahot.chili-mango.net

Is there a way to transfer binary files from the app server to the web browser? By using %Response.WriteBinary() and providing the correct content-type, I could use a separate iScript for serving binary data from tables (images or attachment records). The problem is, there seems to be no way to read binary from files to be used by PeopleCode, specifically as an argument to %Response.WriteBinary(). Is there?

The only option that I know that work is to use attachment functions to copy the desire file to an attachment repository and use attachment functions to serve the file to the browser. However, I'm wondering whether there are better option than this.

This is just something I've been pondering for some time, not exactly related to this blog post. I know it is probably unwise in technique you've presented to include binary files.

January 30, 2007

 

 

 

**********************************************************************

CONFIDENTIALITY: This communication, including attachments, is for the exclusive use of the

addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended

recipient, any use, copying, disclosure, or distribution or the taking of any action in reliance upon this

information is strictly prohibited. If you are not the intended recipient, please notify the sender

immediately and delete this communication and destroy all copies.

**********************************************************************

 

LDAP GOOD COMMAND LINE TEST

ldapsearch -v -s base -h stadc0003.xl -p 3268 -D "CN=sxlpsfin,OU=Accounts,OU=Corporate,DC=xl" -w "Peoplesoft2007" "sn=sxlpsfin"

**********************************************************************

CONFIDENTIALITY: This communication, including attachments, is for the exclusive use of the

addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended

recipient, any use, copying, disclosure, or distribution or the taking of any action in reliance upon this

information is strictly prohibited. If you are not the intended recipient, please notify the sender

immediately and delete this communication and destroy all copies.

**********************************************************************

 

LDAPSEARCH

 

 

 

ldapsearch -v -s base -h stadc0003.xl -p 3268 -D "CN=sxlpsfin,OU=Accounts,OU=Corporate,DC=xl" -w "Peoplesoft2007"  samaccountname=x042258

 

 

 

**********************************************************************

CONFIDENTIALITY: This communication, including attachments, is for the exclusive use of the

addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended

recipient, any use, copying, disclosure, or distribution or the taking of any action in reliance upon this

information is strictly prohibited. If you are not the intended recipient, please notify the sender

immediately and delete this communication and destroy all copies.

**********************************************************************

 

full stats

EXEC dbms_stats.gather_schema_stats('XLPSOFT', cascade=>TRUE);

 

exec dbms_stats.gather_schema_stats( -
ownname          => 'SCOTT', -
options          => 'GATHER AUTO', -
estimate_percent => dbms_stats.auto_sample_size, -
method_opt       => 'for all columns size repeat', -
degree           => 15 -
)

 

 

EXEC dbms_stats.gather_table_stats('SCOTT','EMP',cascade=>TRUE);

 

**********************************************************************

CONFIDENTIALITY: This communication, including attachments, is for the exclusive use of the

addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended

recipient, any use, copying, disclosure, or distribution or the taking of any action in reliance upon this

information is strictly prohibited. If you are not the intended recipient, please notify the sender

immediately and delete this communication and destroy all copies.

**********************************************************************