problem in exit status of the command in a shell script-FTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem in exit status of the command in a shell script-FTP
# 1  
Old 09-07-2009
problem in exit status of the command in a shell script-FTP

Hi All,

I have developed below script for FTP a file from unix machine to another machine.

ftpToABC ()
{

USER='xyz'
PASSWD='abc'
echo "open xx.yy.zbx.aaa
user $USER $PASSWD
binary
echo "put $1 abc.txt" >> /home/tmp/ftp.$$
echo "quit" >> /home/tmp/ftp.$$
ftp -ivn < /home/tmp/ftp.$$ > /home/temp/ftptraceUnix.$$
if [[$? -ne 0 ]]; then

echo "FTP is failed trying to send the file again"
ftpToABC $1
else
echo "FTP successful.File $1 transferred successfully"
fi

}

Now the problem is even if the file is not transfered it is showing the message as FTP successful. Could you please help me to resolve the problem.
# 2  
Old 09-07-2009
it does a space after the [ ...

Code:
if [[ $? -ne 0 ]]; then

# 3  
Old 09-07-2009
Plus I think you will run into a problem here:
Code:
echo "open xx.yy.zbx.aaa
user $USER $PASSWD
binary
echo "put $1 abc.txt" >> /home/tmp/ftp.$$
echo "quit" >> /home/tmp/ftp.$$

with the echos following "binary".
# 4  
Old 09-07-2009
Please add code tags.

You are checking ftp's exit status and not the status of the files transfer which is different.
Though a file is not transferred, the execution of the ftp client might successfully end which means $? will return 0 { success } if its not with respect to the application.

So, direct the output of ftp client to a logfile and parse that.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Weird Exit Status of shell script

I have a script named check which will read the content of a file and check wether those files exist in the current directory. If so it will have the exit status of 0, otherwise it will have 1. check script: #!/bin/bash if ; then #Check there is enough command line parameters. exit 1... (2 Replies)
Discussion started by: Ray Sun
2 Replies

2. Shell Programming and Scripting

How to get the exit status of a command in nner script to the outer script?

Hi all, I have a shell script inside which i am executing another shell script. In the inner script im executing a command. i want the status of that command in the outer script to perform some validations. How to get its status please help!!1 Im using ksh. (2 Replies)
Discussion started by: Jayaraman
2 Replies

3. Shell Programming and Scripting

store last command exit status in variable in shell script

Hello All My req is to store the exit status of a command in shell variable I want to check whether the file has header or not The header will contain the string DATA_ACQ_CYC_CNTL_ID So I am running the command head -1 $i | grep DATA_ACQ_CYC_CNTL_ID Now I have to check if... (6 Replies)
Discussion started by: Pratik4891
6 Replies

4. Shell Programming and Scripting

Exit status for ftp in CShell

Is there a way in the following CShell code to have ftp give an exit status that can be retrieved to determine if it succeeded or failed? ftp -n logxx.xxxx.xxx.xxx.com <<DO_FTP1 quote user $user_name quote pass $password ascii put $js_file_name bin put $FinalZipFile quit DO_FTP1 ... (1 Reply)
Discussion started by: phudgens
1 Replies

5. Shell Programming and Scripting

How to track exit status of ftp automation

ftp automation code is ftp -v -n -i $host_name << EOF user $u_name $u_pass bi mput $tar_file bye EOF How to check whether the file is successfully transfered or not. Suppose the user name or password is provided wrongly then the code should track the error and ask the end user to enter... (2 Replies)
Discussion started by: Dip
2 Replies

6. Shell Programming and Scripting

Move Command and exit status problem

Hi All, I am using the following code to move files from one folder to another on the remote server: ssh username@server <<EOF cd source_dir find . -type f -name "*.txt" |xargs -n1000 -i{} mv {} dest_dir if then send mail indicating error otherwise echo "success" fi EOF ... (10 Replies)
Discussion started by: visingha
10 Replies

7. UNIX for Dummies Questions & Answers

Move Command and exit status problem

Hi All, I am using the following code to move files from one folder to another on the remote server: ssh username@server <<EOF cd source_dir find . -type f -name "*.txt" |xargs -n1000 -i{} mv {} dest_dir if then send mail indicating error otherwise echo "success" fi EOF ... (1 Reply)
Discussion started by: visingha
1 Replies

8. Shell Programming and Scripting

checking exit status of a shell script

Hi, I have tried with the following code; if ;then echo "Failure." else echo "Success." fi to test the exit status of the test.ksh shell script. But whatever is the exit status of the test.ksh shell script Failure. is always printed. Please help. regards, Dipankar. (2 Replies)
Discussion started by: kdipankar
2 Replies

9. Shell Programming and Scripting

Incorrect Exit Status Returned from FTP command - Help??

I am trying to perform some error handing within a Korn sheel script whilst FTPing a file from one server to another.. The exit status is correctly set to zero, if my script connects to the other server and sends the file.. However, if for whatever reason other than a timeout the script... (3 Replies)
Discussion started by: frustrated1
3 Replies

10. UNIX for Advanced & Expert Users

ftp exit status.

Does ftp from unix have an exit status. In the sense after ftp is invoked and if the ftp fails during file transfer does it exit out with a status other than 0. What is do right now is invoke ftp and right it to a log and then grep for 'File Transferred Sucessfully'. Is this the only way to do it... (1 Reply)
Discussion started by: oracle8
1 Replies
Login or Register to Ask a Question