?
Solved

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

Posted on 2001-07-17
8
Medium Priority
?
829 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

770 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