Useful Unix Utilities

Monday, September 17, 2012 by Ajay Atre



Useful Unix utilities
1.       Submitting a concurrent program using Unix
One can code in the command as CONSUB within the shell script which can submit the concurrent program through shell script directly.

CONCSUB $ORACLEUSERID $RESPAPPLNAME $RESPNAME1 $USERNAME WAIT=N CONCURRENT $PROGAPPLNAME $PROGSHORTNAME1 $PARAM1 $PARAM2 $PARAM3
Where
ORACLEUSERID – oracle apps userid/password. UserID/PWD comes in parameter1
RESPAPPLNAME – Responsibility application name
RESPNAME1 – Responsibility name
USERNAME – Username who is submitting the program
WAIT- If needed waiting time can be added
PROGAPPLNAME- Actual program needs to be submitted
PROGSHORTNAME1- Concurrent program short name
PARAM1, PARAM2, PARAM3- Concurrent program Parameters

2.       Compress the file in Unix
zip archivefile1 doc1 doc2 doc3
Finding the files in Unix
find . -name "*.*" -print | xargs grep "force_line_approval"

3.       Email with attachment from shell script
uuencode $file_name $$file_name |mail -s "$EMAILSUBJECT" $TOADDRESS -- -f $SENDERADDRESS
EMAILSUBJECT- Email Subject
TOADDRESS – To address
SENDERADDRESS – Sender Address
Note:-  you need to install uuencode in your environment.

4.       Get the file size in unix
FILESIZEAFTER=$(du -h $DATA_FILE | awk '{ print $1 }')
echo "... file $FINAL_OUTFILE  size $FILESIZEAFTER"

5.       Trim the spaces of the parameter value
USERPWD=`echo $1 | cut -f3 -d' ' | cut -f2 -d'"'`

6.       Find the file file size
#check file size
   fsize=`wc -c $FINAL_OUTFILE`
   fsize=`echo $fsize | cut -f1 -d' '`
   if test $fsize -ge 1
   then
     echo  "...Data File size > 0 "
   else
     echo  "...Data File size = 0; "
     exit 
   fi
else
   echo "...Data File not found "
   exit 
fi

7.       FTP Download
Mirror the directory
lftp431 -u $FTPUSER,$FTPPASS $FTPSERVER -e "mirror $ONLY_NEWER_OPTION $REVERSE_OPTION $REMOVE_SOURCE_FILES_OPTION $NO_PERMS_OPTION $NO_RECURSION_OPTION --verbose=3 $SOURCEDIR $TARGETDIR; exit"

Note:-  you need to install lftp in your environment. Mirror command will download everything to your local directory (as good as mget).  

8.       FTP Outgoing
1.       SFTP FTP- needs a port number
lftp -u $FTPUSER,$FTPPASS -e "lcd $SOURCEDIR;put $DELETE_OPTION $EDI_OUT_DATA_FILE; exit" $FTPSERVER:22$TARGETDIR
2.       Generic FTP
lftp -u $FTPUSER,$FTPPASS -e "lcd $SOURCEDIR; put $DELETE_OPTION $EDI_OUT_DATA_FILE; exit" $FTPSERVER$TARGETDIR

9.       Compiling the oracle form  under Unix
Exporting the AU_TOP Resource path
export FORMS60_PATH=:FORMS60_PATH:$AU_TOP/resource:$AU_TOP/forms/US
frmcmp_batch module=$CUS_TOP/forms/US/testfrm.fmb userid=apps/apps

R11i Command
f60gen Module=$CUS_TOP/forms/US/ testfrm.fmb Userid=apps/apps compile_all=special
Output_File=$CUS_TOP/forms/US/ testfrm.fmx

10.   Setting the softlink for Unix executables
ln -s $FND_TOP/bin/fndcpesr $CUS_TOP/bin/TESTSCRIPT
Where
TESTSCRIPT- is just the name of the Unix shell script without an extension.

11.   FND LOAD for copying the AOL objects across instances
Download the concurrent program
FNDLOAD apps/apps O Y DOWNLOAD $FND_TOP/patch/115/import/afcpprog.lct /tmp/TESTPROG.ldt PROGRAM APPLICATION_SHORT_NAME="CUSTOP" CONCURRENT_PROGRAM_NAME=" TESTPROG "

FNDLOAD apps/apps O Y UPLOAD $FND_TOP/patch/115/import/afcpprog.lct /tmp/ TESTPROG.ldt

11.    SQL LOADER Example
sqlldr control=test.ctl userid=$LOGIN data=$ FILEDIR/$ DATA_FILE log=TEST.log

retcode=`echo $?`; export retcode
case "$retcode" in
0) echo "SQL*Loader execution successful" ;;
1) echo "SQL*Loader execution exited with EX_FAIL, see logfile TEST.log" ;;
2) echo "SQL*Loader execution exited with EX_WARN, see logfile TEST.log"
   echo "All the records in $DATA_FILE will not be processed by this program"
   RET_FLAG=1 ; export RET_FLAG
   ;;
3) echo "SQL*Loader execution encountered a fatal error for $ DATA_FILE" ;;
*) echo "unknown return code for while processing";;
esac


12.   Append files into single file
# -----------------------------------------------------------------------------+
# append files into one new file                                               +
# -----------------------------------------------------------------------------+
FIRST_FILE="Y"

for FILE in `ls -1 $IN_FILE_PATH/$FILE_PATTERN`
do

   # --------------------------------------------------------------------------+
   # get File Name by removing the path                                        +
   # --------------------------------------------------------------------------+
   FILE_NAME=`echo $FILE| awk -F\/ '{print $NF}' `

#   echo "Data File name... $FILE_NAME"

   # --------------------------------------------------------------------------+
   # get Backup File Name                                                      +
   # --------------------------------------------------------------------------+
   BK_FILE_NAME=`date +$FILE_NAME.%Y%m%d%H%M%S`
  
   echo "...Inbound Data File name: $FILE_NAME - ...Archive Data File name: $BK_FILE_NAME"

   # --------------------------------------------------------------------------+
   # append files to one new file                                              +
   # --------------------------------------------------------------------------+
   if [ "$FIRST_FILE" = "Y" ]
   then
      cat $FILE > $NEW_FILE
      FIRST_FILE="N"
   else
      cat $FILE >> $NEW_FILE
   fi

   # --------------------------------------------------------------------------+
   # move File to backup directory                                             +
   # --------------------------------------------------------------------------+
   mv $FILE $BK_DIR/$BK_FILE_NAME
done

Filed under , having 0 comments