红联Linux门户
Linux帮助

请高手帮忙看看这段脚本,据说是不合适red hat

发布时间:2011-01-25 16:20:25来源:红联作者:hl02560
请高手帮忙看看这段脚本,据说是不合适red hat ,能否帮忙更新一下以适合red hat,谢谢!
文章评论

共有 2 条评论

  1. ouc_wentao 于 2011-01-26 12:00:48发表:

    我晕 好长 看不懂

  2. 相思爱文 于 2011-01-25 22:00:12发表:

    [i=s] 本帖最后由 相思爱文 于 2011-1-25 22:04 编辑 [/i]

    我不懂,把附件内容列出来了。[code]# SWFTP

    #

    # This program is designed to handle only parameters passed from concurrent

    # request. It is not designed to be called or handle parameters from command line.

    #

    # Paramaters 0-4 are from Concurrent Manager

    # 0 - Name of the Concurrent Program

    # 1 - Oracle User ID/PASSWORD

    # 2 - User ID/PASSWORD

    # 3 - User Name that submitted the request

    # 4 - Request ID for the request

    # 5 - Remote Server Name (Required)

    # 6 - Remote FTP User ID (Required)

    # 7 - Remote FTP User Password (Required)

    # 8 - Remote FTP Server Action (GET, PUT, MPUT, MGET) (Required)

    # 9 - Remote FTP Server Path (Required)

    # 10 - File or Extension (File or Extension) (Required)

    # 11 - Local Path to GET file FROM or PUT file TO (Required)

    # 12 - Remote Rename Extension (Optional))

    # 13 - Local Rename Extension (Optional)

    # 14 - Local Move Path (Optional)

    # 15 - UNIX format date stamp (Optional)

    #Retrieve Parameters from concurrent program

    conc_prog_name="${0}"

    conc_ora_userid_pwd="${1}"

    conc_userid_pwd="${2}"

    conc_submitter="${3}"

    conc_request_id="${4}"

    conc_remote_server="${5}"

    conc_remote_userid="${6}"

    conc_remote_password="${7}"

    conc_remote_action="${8}"

    conc_remote_path="${9}"

    shift $6

    conc_remote_file_or_extension="${4}"

    conc_local_path="${5}"

    conc_remote_rename_extension="${6}"

    conc_local_rename_extension="${7}"

    conc_local_move_path="${8}"

    conc_unix_date_mask="${9}"

    # Additional local parameters

    l_conc_log_path=${APPLCSF}/${APPLLOG}

    l_conc_log_file_name="l${conc_request_id}.req"

    l_request_output="${l_conc_log_path}/${l_conc_log_file_name}"

    #UNIX return status from various program calls

    l_error_occurred=0

    #We add the concurrent request id as a working extension on GET and MGET

    #This flag indicates whether extension was added or not in order to strip it back off

    #This flag will be set to 1(True) when extension is added or 0(False) when it is not

    l_extension_added=0

    #Create a time stamp to add to end of l_list_of_files when they are moved if

    #conc_unix_date_mask is provided

    if [ ${conc_unix_date_mask} != '' ]

    then

    l_date_stamp=".$(date +${conc_unix_date_mask})."

    else

    l_date_stamp='.'

    fi

    # Start the log file header

    printf "==================================================\n">${l_request_output}

    printf "Begin Concurrent Request # %s \n" ${conc_request_id}>>${l_request_output}

    printf "==================================================\n">>${l_request_output}

    printf "\tRemote FTP Action: ${conc_remote_action}\n">>${l_request_output}

    case ${conc_remote_action} in

    "GET")

    if [ -z "${conc_local_move_path}" ] && [ -z "${conc_local_rename_extension}" ] && [ -z "${conc_unix_date_mask}" ]

    then

    printf "\tMust provide either a local move path, a local rename extension or a date mask for a GET! GET will not execute\n">>${l_request_output}

    exit 1

    else

    printf "\t\tGetting file ${conc_remote_file_or_extension}\n" >> ${l_request_output}

    printf "\t\t\t\tAdding extension '${conc_request_id}' for processing\n">>${l_request_output}

    #This is a GET, so we will be adding a working extension of the request

    #id so flag it as TRUE

    l_extension_added=1

    #Add the extension name of the concurrent request id onto the file

    #we are doing the GET on

    l_local_renamed_file=${conc_remote_file_or_extension}.${conc_request_id}



    ftp -niv ${conc_remote_server} <> ${l_request_output}

    user ${conc_remote_userid} ${conc_remote_password}

    cd ${conc_remote_path}

    pwd

    lcd ${conc_local_path}

    get ${conc_remote_file_or_extension} ${l_local_renamed_file}

    bye

    !EOF

    #Searching Successful Transfer Status Code # 226 in the Log file

    f=$(more ${l_request_output} | grep 226 | wc -l)



    #Searching for Permission denied status

    g=$(more ${l_request_output} | grep "Permission denied" | wc -l)



    #Searching for valid file or directory status

    h=$(more ${l_request_output} | grep "No such file or directory" | wc -l)

    if [ $f -eq 0 ] || [ $g -ne 0 ] || [ $h -ne 0 ]

    then

    print "\t\t\tERROR: FTP GET failed on ${conc_remote_file_or_extension}\n">>${l_request_output}

    l_error_occurred=1

    else



    #FTP again to delete the file on the remote machine if successful GET is performed

    ftp -niv ${conc_remote_server} <> ${l_request_output}

    user ${conc_remote_userid} ${conc_remote_password}

    cd ${conc_remote_path}

    pwd

    delete ${conc_remote_file_or_extension}

    bye

    !EOF



    print "\t\t\tSUCCESS: FTP GET successful on ${conc_remote_file_or_extension}\n" >>${l_request_output}

    fi

    fi

    ;;

    "MGET")

    if [ -z "${conc_local_move_path}" ] && [ -z "${conc_local_rename_extension}" ] && [ -z "${conc_unix_date_mask}" ]

    then

    printf "\tMust provide either a local move path, a local rename extension or a date mask for an MGET! MGET will not execute\n">>${l_request_output}

    exit 1

    else

    printf "\t\tGetting file(s) matching ${conc_remote_file_or_extension}\n" >> ${l_request_output}

    printf "\t\t\t\tAdding extension '${conc_request_id}' for processing\n">>${l_request_output}

    #This is a MGET, so we will be adding a working extension of the request

    #id so flag it as TRUE

    l_extension_added=1



    ftp -niv ${conc_remote_server} <> ${l_request_output}

    user ${conc_remote_userid} ${conc_remote_password}

    cd ${conc_remote_path}

    pwd

    lcd ${conc_local_path}

    nmap \$0 \$0.${conc_request_id}

    mget ${conc_remote_file_or_extension}

    bye



    !EOF



    f=$(more ${l_request_output} | grep 226 | wc -l)

    g=$(more ${l_request_output} | grep "Permission denied" | wc -l)

    h=$(more ${l_request_output} | grep "No such file or directory" | wc -l)



    if [ $f -eq 0 ] || [ $g -ne 0 ] || [ $h -ne 0 ]

    then

    print "\t\t\tERROR: FTP MGET failed on ${conc_remote_file_or_extension}\n">>${l_request_output}

    l_error_occurred=1

    else

    print "\t\t\tSUCCESS: FTP MGET successful on ${conc_remote_file_or_extension}\n">>${l_request_output}

    #FTP again to delete the file on the remote machine if successful GET is performed

    ftp -niv ${conc_remote_server} <> ${l_request_output}

    user ${conc_remote_userid} ${conc_remote_password}

    cd ${conc_remote_path}

    pwd

    mdelete ${conc_remote_file_or_extension}

    bye

    !EOF

    fi

    fi

    ;;

    "PUT"|"MPUT")

    printf "\t\t\t\t"

    #This is a PUT, so we will not be adding a working extension of the

    #request id so flag it as FALSE

    l_extension_added=0

    printf "\t\tPutting file(s) matching ${conc_remote_file_or_extension}\n" >> ${l_request_output}





    l_files_to_put=`ls ${conc_local_path}/${conc_remote_file_or_extension} 2> /dev/null`



    #Check for valid directory

    if [ ! -d ${conc_local_path} ]

    then

    printf "\t\t Invalid Path ${conc_local_path} \n"

    exit 1

    fi



    #Check for valid files or extension

    if [ -z "${l_files_to_put}" ]

    then

    printf "\n Invalid File name, extension OR File not Exists :: ${conc_remote_file_or_extension} \n"

    exit 1

    fi



    for l_file_name in ${l_files_to_put}

    do

    l_file_basename=`basename ${l_file_name}`

    printf "\t\tPutting file ${l_file_basename}\n" >> ${l_request_output}

    if [ -z "${conc_remote_rename_extension}" ]

    then

    printf "\t\t\tRemote rename not provided\n">>${l_request_output}

    printf "\t\t\t\t"

    ftp -niv ${conc_remote_server} <>${l_request_output}

    user ${conc_remote_userid} ${conc_remote_password}

    cd ${conc_remote_path}

    pwd

    lcd ${conc_local_path}

    put ${l_file_basename}

    bye

    !EOF

    f=$(more ${l_request_output} | grep 226 | wc -l)

    g=$(more ${l_request_output} | grep "${l_file_basename}: Permission denied" | wc -l)

    h=$(more ${l_request_output} | grep "${l_file_basename}: No such file or directory" | wc -l)



    if [ $f -eq 0 ] || [ $g -ne 0 ] || [ $h -ne 0 ]

    then

    print "\t\t\tERROR: FTP PUT failed on ${l_file_basename}\n">>${l_request_output}

    l_error_occurred=1

    else

    print "\t\t\tSUCCESS: FTP PUT successful on ${l_file_basename}\n" >>${l_request_output}

    fi

    else

    printf "\t\t\tRemote rename provided\n">>${l_request_output}

    l_file_basename_exclude_extension=${l_file_basename%\.*}

    printf "\t\t\t\tWill be renamed to ${l_file_basename_exclude_extension}.${conc_remote_rename_extension}\n">>${l_request_output}

    printf "\t\t\t\t"

    ftp -niv ${conc_remote_server} <>${l_request_output}

    user ${conc_remote_userid} ${conc_remote_password}

    cd ${conc_remote_path}

    pwd

    lcd ${conc_local_path}

    put ${l_file_basename}

    rename ${l_file_basename} ${l_file_basename_exclude_extension}.${conc_remote_rename_extension}

    bye

    !EOF



    f=$(more ${l_request_output} | grep 226 | wc -l)

    g=$(more ${l_request_output} | grep "${l_file_basename}: Permission denied" | wc -l)

    h=$(more ${l_request_output} | grep "${l_file_basename}: No such file or directory" | wc -l)



    if [ $f -eq 0 ] || [ $g -ne 0 ] || [ $h -ne 0 ]

    then

    print "\t\t\tERROR: FTP PUT failed on ${l_file_basename}\n">>${l_request_output}

    l_error_occurred=1

    else

    print "\t\t\tSUCCESS: FTP PUT successful on ${l_file_basename}\n" >>${l_request_output}

    fi

    fi

    done

    ;;

    *)

    printf "\t\tERROR: FTP Action '${conc_remote_action}' not recognized\n" >> ${l_request_output}

    l_error_occured=1

    ;;

    esac



    if [ ${l_error_occurred} -eq 0 ]

    then

    printf "\tFTP Session Ended Successfully\n">>${l_request_output}

    else

    printf "\tFTP Session ERROR\n">>${l_request_output}

    exit 1



    fi



    #Optionally move and/or rename files locally for all operations

    if [ -z "${conc_local_move_path}" ] && [ -z "${conc_local_rename_extension}" ] && [ -z "${conc_unix_date_mask}" ]

    then

    printf "\tNo local path, local extension or date mask were provided, file(s) will not be moved or renamed\n">>${l_request_output}

    else

    if [ ${l_extension_added} -eq 1 ]

    then

    #On GET or MGET we have used nmap to add the concurrent request id

    #as an extension to our local files. As such we can list those files

    #searching with a wildcard and then we will remove the concurrent

    #request id extension.

    l_list_of_files=`ls ${conc_local_path}/*.${conc_request_id} 2> /dev/null`

    l_list_of_files_count=`ls ${conc_local_path}/*.${conc_request_id} | wc -l`

    else

    l_list_of_files=`ls ${conc_local_path}/${conc_remote_file_or_extension} 2> /dev/null`

    l_list_of_files_count=`ls ${conc_local_path}/${conc_remote_file_or_extension} | wc -l`

    fi



    if [ l_list_of_files_count > 0 ]

    then

    printf "\t\t${l_list_of_files_count} file(s) were found\n">>${l_request_output}

    for l_file_name in ${l_list_of_files}

    do

    #This will return the file name with the full path removed

    l_file_basename=`basename ${l_file_name}`

    if [ ${l_extension_added} -eq 1 ]

    then

    print "\t\tStripping off extension ${conc_request_id}">>${l_request_output}

    #This will strip off the last extension on the file

    l_file_basename_stripped=${l_file_basename%\.*}

    else

    l_file_basename_stripped=${l_file_basename}

    fi



    #This will return the last extension on the file

    l_file_basename_extension=${l_file_basename_stripped##*\.}

    #This will strip off the last extension on the file

    l_file_basename_exclude_extension=${l_file_basename_stripped%\.*}



    #Move path is empty, but local extension was provided

    if [ -z "${conc_local_move_path}" ] && [ -n "${conc_local_rename_extension}" ]

    then

    printf "\tMove Path was empty, but local extension was provided\n">>${l_request_output}

    l_file_path=${conc_local_path}

    l_file_extension=${conc_local_rename_extension}

    #Move path was provided, but local extension was empty

    elif [ -n "${conc_local_move_path}" ] && [ -z "${conc_local_rename_extension}" ]

    then

    printf "\tMove Path was provided, but local extension was empty\n">>${l_request_output}

    l_file_path=${conc_local_move_path}

    l_file_extension=${l_file_basename_extension}

    # Move path was empty and local extension was empty

    elif [ -z "${conc_local_move_path}" ] && [ -z "${conc_local_rename_extension}" ]

    then

    printf "\tMove Path was empty and local extension was empty\n">>${l_request_output}

    l_file_path=${conc_local_path}

    l_file_extension=${l_file_basename_extension}

    #Move path was provided, and local extension was provided

    else

    printf "\tMove Path was provided, and local extension was provided\n">>${l_request_output}

    l_file_path=${conc_local_move_path}

    l_file_extension=${conc_local_rename_extension}

    fi



    mv ${conc_local_path}/${l_file_basename} ${l_file_path}/${l_file_basename_exclude_extension}${l_date_stamp}${l_file_extension}

    if [ $? -ne 0 ]

    then

    l_error_occurred=1

    printf "\t\tFile not moved! Unable to move ${conc_local_path}/${l_file_basename} to ${l_file_path}/${l_file_basename_exclude_extension}${l_date_stamp}${l_file_extension}\n">>${l_request_output}

    else

    printf "\t\tMoved ${conc_local_path}/${l_file_basename} to ${l_file_path}/${l_file_basename_exclude_extension}${l_date_stamp}${l_file_extension}\n">>${l_request_output}

    fi

    printf "\n">>${l_request_output}

    done

    fi

    fi



    exit ${l_error_occured}
    [/code]