[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2001-07-17
8
Medium Priority
?
842 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
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!

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

650 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