0

I am doing an ftp and I want to check the status. I don't want to use '$?' as mostly it returns 0 (Success) for ftp even though internally ftp didn't go through.

I know I can check the log file and do a grep from there for "Transfer complete" (221 status). That works fine but I don't want to do it as I have many different reports doing ftp. So creating multiple log files for all of them is what I want to avoid.

Can I get the logged information in a local script variable and process it inside the script itself? Something similar to these (I've tried both but neither worked):

Below is something similar to what I am trying to do:

ftp -inv ${HOST} > log_file.log  <<! 
user ${USER} ${PASS}
bin
cd "${TARGET}"
put ${FEEDFILE}
bye
!

Any suggestions on how can I get the entire ftp output in a script variable and then check it within the script?

2
  • 1
    You say "didn't work"; you don't explain in what way they didn't work. Was the output not written to your log file? Was the output not written at all? Was it written to standard error instead of standard output? Commented Sep 6, 2017 at 0:50
  • If I create a variable and equate it to the ftp command. Nothing is being returned. Variable is still empty. Something like this STATUS=ftp -n $HOST > log_file.log <<! USER $USER PASS $PASSWD cd /user/sba-appl/test bye EOF'` here STATUS is empty. I want my variable to get what is being logged in the log file. Sorry for inappropriate code structure. Commented Sep 6, 2017 at 2:32

1 Answer 1

1

To capture stdout to a variable you can use bash's command substitution, so either OUTPUT=`cmd` or OUTPUT=$(cmd).

Here's an example how to capture the output from ftp in your case:

CMDS="user ${USER} ${PASS}
bin
cd \"${TARGET}\"
put \"${FEEDFILE}\"
bye"

OUTPUT=$(echo "${CMDS}" | ftp -inv ${HOST})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.