By nmm_dba
Please help me do the following
The script does the following:
– check directory exists
– copy dump files
– copy is done for multiple database
– checks databases, if one database does not exist, the script should skip that database and move to the next database.
Started the script:
==============
#!/usr/bin/ksh
# *****************************************************************************
# Script Name: sftp_dump_files.ksh
# Description: Performs sFTP put of exported dump files
#
# Syntax:
# sftp_dump_files.ksh -d -r
#
# Required parameters:
# lv_dbname - name of schema dump to sFTP
# lv_rfc - change number [ format CHGXXXX ]
# *****************************************************************************
#
# Execute to setup global variables
. ${APPS}/db_batch/common/.batchenv
# *****************************************************************************
# Function - Display parameter usage and terminate the job
# *****************************************************************************
CMD=`basename $0`
display_usage()
{
echo "==============================================================================="
echo "Script Name: ${CMD}"
echo "Description: Performs sFTP put of exported dump files"
echo ""
echo "Usage:"
echo " ${CMD} -r "
echo ""
echo "Required parameters:"
echo " lv_dbname - name of database dump to sFTP"
echo " lv_rfc - change number [ format CHGXXXX ]"
echo "==============================================================================="
exit 1
}
# *****************************************************************************
# Parse input parameter
# *****************************************************************************
set -- $(getopt u:r: $*)
if [ $? -ne 0 ]
then
echo "ERROR: Insufficient arguments."
display_usage
fi
count_r=0
for o in $(getopt u:r: $*)
do
case $o in
-u) lv_dbname="$2"; count_u=$(expr $count_u + 1); shift 2;;
-r) lv_rfc="$2"; count_r=$(expr $count_r + 1); shift 2;;
--) shift; break;;
esac
done
# Abort if there are insufficient arguments
if [ $count_u -ne 1 ] || [ $count_r -ne 1 ]
then
echo "ERROR: Insufficient arguments."
display_usage
fi
# Export local variables and force uppercase
export lv_dbname="`echo ${lv_dbname} | tr '[:lower:]' '[:upper:]'`"
export lv_rfc="`echo ${lv_rfc} | tr '[:lower:]' '[:upper:]'`"
# *****************************************************************************
# Setup local step variables
# *****************************************************************************
# Local job variables
export lv_job_path="${DBBATCH}/CR/${lv_rfc}"
export lv_common_path="${lv_job_path}/common"
export lv_shell_path="${lv_job_path}/shell"
export lv_sql_path="${lv_job_path}/sql"
export lv_log_path="${lv_job_path}/log"
mkdir -p ${lv_common_path} ${lv_shell_path} ${lv_sql_path} ${lv_log_path}
# Setup local step variables
lv_step_name=sftp_dump_files
lv_step_log_file=${lv_log_path}/${lv_step_name}.log
# Additional local variables
lv_retcode=0
lv_exitcode=0
# *****************************************************************************
# Main
From: http://www.unix.com/shell-programming-scripting/221615-sftp-files-between-servers.html