Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6862347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:39:03+00:00 2026-05-27T02:39:03+00:00

notice the FTP_PUT_RETVAL . There are two echo commands, the first one shows a

  • 0

notice the FTP_PUT_RETVAL. There are two echo commands, the first one shows a value of ‘0’. The second one shows no value at all. I am running this inside a nightly cron. BASH is GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)

My script tells me that the ftp upload was unsuccessful, because FTP_PUT_RETVAL contains no value!

Why is this occuring? How can I change this? What have I done wrong?

    #!/bin/sh
    #
    # Filename: rh5-manager-cron.sh
    #
    # Purpose: Runs backup.cron, and FTP uploads backup to Linux4
    #
    # Usage: the program is run with no arguments. This program is
    # intended to run from manager cron, and redirection is handled inside the cron
    #     e.g. 00 1 * * * /u2/app/lbin/rh5-manager-cron.sh > /tmp/log/rh5-manager-cron.log 2>&1
    trap signalCaught ABRT EXIT HUP INT PIPE TERM QUIT
    signalCaught () {
        for file in $FTP_LOG_FILE $TMPF; do
            $BIN_HOME/rm_file $TMPF
        done
        exit
    }

    if [[ ! -r /u2/conf/ctrl/lettus.sh || ! -r /u2/app/lbin/fsh_sh_lib ]]; then
        printf "Cannot source environment.\n" >&2
        exit 1
    fi
    . /u2/conf/ctrl/lettus.sh
    . /u2/app/lbin/fsh_sh_lib

    #-------------------------------------------------------
    # Variables
    #-------------------------------------------------------
    PRG=${0##*/}
    FTPUSER=dummy
    FTPPASS=dummy
    FTPHOST=192.168.0.3
    BACKUPDIR=/backup
    FTPBACKUPNAME=Redhat5Backup.tgz
    FTPBACKUPFILE=$BACKUPDIR/$FTPBACKUPNAME
    LOGDIR=/tmp/log
    FTP_LOG_FILE=$LOGDIR/Redhat5FTP.log
    SENDLOGS=$C/sendlogs.dat
    ZOOT_XML=$C/zoot.xml
    TMPF=`mktemp` || exit 1

    #-------------------------------------------------------
    # Sanity
    #-------------------------------------------------------
    if ! isValidUser root manager; then
        printf "$PRG: Must be run as user 'root' or user 'manager'.\n" >&2
        exit 1
    fi

    if [[ ! -d $BACKUPDIR ]]; then
        logger "$PRG: $BACKUPDIR: Not a valid directory" >&2
        exit 1
    fi

    if [[ ! -d $LOGDIR ]]; then
        logger "$PRG: $LOGDIR: Not a valid directory" >&2
        exit 1
    fi

    if [[ ! -r $SENDLOGS || ! -r $ZOOT_XML ]]; then
        logger "$PRG: E-mail: Files are not readable: $SENDLOGS, $ZOOT_XML" >&2
        exit 1
    fi

    if ! which lftp >/dev/null 2>&1; then
        logger "$PRG: lftp: command not found" >&2
        exit 1
    fi

    # e-mail
    EMAIL_SUBJECT="Redhat5 FTP PUT"
    EMAIL_TO=$(email_to $SENDLOGS)
    EMAIL_FROM=$(email_from $ZOOT_XML)

    # ftp binary
    LFTP_BIN=$(which lftp 2>/dev/null)

    #-------------------------------------------------------
    # Functions
    #-------------------------------------------------------

    # calls lftp to upload a file to server non-interactively
    ftp_put() {
        $LFTP_BIN $LFTP_DEBUG -u ${FTPUSER},${FTPPASS} $FTPHOST <<-EOF
    put $FTPBACKUPFILE
    pwd
    ls $FTPBACKUPNAME
    quit
    EOF
    #^^^^^^^^^^^ leave the above indentation alone
    }

    main() {
        # Backup, and send manager logs
        logger "Running backup.cron..."
        echo
        backup.cron
        BACKUP_CRON_RETVAL=$?

        logger "Running fsh_sendlogs..."
        echo
        $SH_HOME/fsh_sendlogs 1

        # show ls listing
        logger "Here comes a directory listing..."
        echo
        /bin/ls -l /backup/Redhat5Backup.tgz
        echo

        # ftp upload
        logger "Running ftp upload..."
        echo
        ftp_put
        FTP_PUT_RETVAL=$?
        echo " -- debug: Line ${LINENO:-}: FTP_PUT_RETVAL=${FTP_PUT_RETVAL:-}"
    }

    checkSuccess() {
        if [[ "$BACKUP_CRON_RETVAL" -eq 0 ]]; then
            echo "Backup was successful."
            echo
            echo "*********************************"
            echo "   OK: Backup was successful."
            echo "*********************************"
            echo
        else
            echo "ERROR: Backup FAILED! "
            echo
            echo "*********************************"
            echo "     ERROR: Backup FAILED! "
            echo "*********************************"
            echo
        fi

        echo " -- debug: Line ${LINENO:-}: FTP_PUT_RETVAL=${FTP_PUT_RETVAL:-}"
        if [ "$FTP_PUT_RETVAL" -eq 0 ]; then
            echo "lftp: ftp file upload complete."
            echo
            echo "*********************************"
            echo "  OK: ftp file upload complete."
            echo "*********************************"
            echo
        else
            echo "lftp: error ftp file upload not successful."
            echo
            echo "*********************************"
            echo "      ERROR: file upload"
            echo "       NOT successful."
            echo "*********************************"
            echo
        fi
    }

    email_logs() {
        if [[ -z "$EMAIL_FROM" || -z $EMAIL_TO || -z $EMAIL_SUBJECT || ! -r $FTP_LOG_FILE ]]; then
            logger "$PRG: One of the variables is not correctly configured" >&2
            exit 1
        fi
        fsh_mail -r "${EMAIL_TO}" -F "${EMAIL_FROM}" -s "${EMAIL_SUBJECT}" -t "${FTP_LOG_FILE}"
        return
    }

    #----------------------------------------------------------------------
    # Main Program
    #----------------------------------------------------------------------
    main               | tee $FTP_LOG_FILE
    checkSuccess       | tee -a $FTP_LOG_FILE $TMPF
    cat $FTP_LOG_FILE >> $TMPF

    # E-mail ftp log file
    logger "Emailing ftp logfile"
    echo
    email_logs

    #eof
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:39:03+00:00Added an answer on May 27, 2026 at 2:39 am

    The problem is that you are using:

    main               | tee $FTP_LOG_FILE
    checkSuccess       | tee -a $FTP_LOG_FILE $TMPF
    

    Because of the piping, the work done in main is done in a sub-shell, and a sub-shell cannot set variables in the parent shell. So, when checkSuccess (which is also run in a sub-shell) goes to look at the results, it sees what was in the parent shell (nothing), rather than what was set in the main function in a sub-shell.

    If you dropped the piping, it would start to work.

    More reliably, put the call to checkSuccess into the main function. Or use one or the other of these two notations:

    { main; checkSuccess; } | tee $FTP_LOG_FILE $TMPF
    ( main; checkSuccess )  | tee $FTP_LOG_FILE $TMPF
    

    Note that the { ... } notation requires a semi-colon after the second function which the ( ... ) notation does not require. However, there is one less process involved in the { ... } mechanism, not that it is going to make any measurable difference to the overall performance of this (the FTP time will dominate).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Notice the nested subqueries. I know there's a better way to make this happen
i notice there's this functionality on 9gag.com. on the homepage, the 'Y u no
Notice in the bottom right hand corner of this page it has the SVN
Notice these two RedHat Linux system configuration settings: $ getconf GNU_LIBC_VERSION glibc 2.3.4 $
Ok this is weird on my development server if I am running a test
Notice, this is a remote server, I don't have access to it, only to
NOTICE This is a rather large question, so please bear with me and I
Notice this app: How can I draw that sort of triangle above an existing
I notice something strange happens to one of my view controller: the back button
Anyone notice slowness from a django dev server running on Mac OS and connecting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.