Solved

How to get the return status of ftp command in UNIX KSH script?

Posted on 2001-07-17
8
824 Views
Last Modified: 2013-12-26
#!/bin/ksh
#Syntax to execute this script
#<programsName> icrt <path & from filename> <To path & FileName>


working_dir="/home/aclem01"

. $working_dir/.profile

# cd to work directory
cd $working_dir

# Which system to transfer to
if test $1 = "icrt"
then
                  ftp -in 101.215.181.180 <<ENDFTP
                  user <username> <password>
                  cd //home/aclem01
                  ascii
                  put $2 $3
                  quit
ENDFTP
          if [ $? -ne 0 ]
          then
              echo "$2 File is not transferd to $1"
              return 2
          fi
          echo "$2 File transferd to $1"
fi




when i execute this script,  "$?" always returns ZERO, even if the above ftp fails. How can get the return status of the ftp process inorder to print the success/failure message to the user?
Please some one help me.
0
Comment
Question by:mogunek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 5

Expert Comment

by:marecs
ID: 6292756
the man page for ftp does not mention anyrthing about the exit status. Try this

ftp -inv 101.215.181.180 <<ENDFTP |grep '226 Transfer complete'

0
 

Author Comment

by:mogunek
ID: 6296391
I am unable to use like this, this is giving syntax error in the script.

Is there any other way to get the return status of get/put function within the ftp block.
Thanks,
0
 
LVL 3

Expert Comment

by:mrn060900
ID: 6317292
after the put,
do a get to a temporary dir and filename,
then do a test -s filename,
then rm the file from the temp dir

Not the best way, but a work around

Regards Mike

www.unixonline.co.uk
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:paulqna
ID: 6330346
I think this would be a better workaround...

http://www.columbia.edu/kermit/ftpscripts.html
0
 

Expert Comment

by:rajiv_indya
ID: 6333005
ANSWER:


if [ $? -ne 0 ]
this "$?" will give the status of "ftp" command which was successful , after that control goes to ftp.

Do this for solution :
before quit add following lines

lcd /temp
get $3

after ENDFTP add

if [ -f $3 ]
then
    echo "File transferd "
    rm $3
else
    echo "Error"
fi

0
 
LVL 4

Expert Comment

by:Otetelisanu
ID: 6348003
If is a error in the
ftp transfer (put or get) the error
is not in ($?) exit error.
Exit error is only 0.

1.Make ftp with debug.
2. Make a script when you compare
   the filebytes with ftp debug bytes

0
 
LVL 21

Expert Comment

by:tfewster
ID: 8191431
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- PAQ, no points refunded

Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster
Cleanup Volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8241138
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question