The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 01-25-2008
KittyWu KittyWu is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 8
Hi,

this script (Korn shell) targets these 2 problems:

# [BEGIN script] -----------------------------------------

# 1. Extract the data from the DB

typeset DB_VALUEs=$(sqlplus -s YOUR_USER_NAME/YOUR_USER_PASSWORD@YOUR_DB_NAME <<ENDSQL
set echo off
set lines 120 pages 120 feedback off
SET HEADING OFF

select YOUR_COLUMNs from YOUR_TABLE;
ENDSQL
)

# Remove newline characters
DB_VALUEs=$(echo ${DB_VALUEs})
#echo "DB_VALUEs = '${DB_VALUEs}'"


# 2. FTP a single file

# Create a temporary file for the FTP dialog
typeset TMP_FILE=$(mktemp); RC=$?
if [[ ${RC} -ne 0 ]]; then
echo "ERROR: cannot create a temporary file... (RC=${RC})"
exit ${RC}
fi

# Create a temporary file for the FTP output
typeset OUT_FILE=$(mktemp); RC=$?
if [[ ${RC} -ne 0 ]]; then
echo "ERROR: cannot create a temporary file... (RC=${RC})"
exit ${RC}
fi

# Run the FTP command ()
cat >${TMP_FILE} <<!
open YOUR_FTP_SERVER_NAME
user YOUR_FTP_USER_NAME YOUR_FTP_USER_PASSWORD
binary
lcd YOUR_LOCAL_FILE_DIRECTORY
put YOUR_FILE_NAME
close
!
ftp -n <${TMP_FILE} > ${OUT_FILE}

echo "RESULT code: '$?'"

rm ${TMP_FILE}

echo "RESULTs:"
cat ${OUT_FILE}
rm ${OUT_FILE}

# [END script] -------------------------------------------

where the 'YOUR_xxx' strings should be customized.

Please tell me if it works and if it fits your needs.

C.