获取退出状态code从“FTP”命令在Linux的shell [英] Getting exit status code from 'ftp' command in linux shell

查看:302
本文介绍了获取退出状态code从“FTP”命令在Linux的shell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从一个命令行程序retrive退出状态code。不用担心,我用$?
但对于FTP,即使不连接,它打开ftp的外壳,所以我不能够理解的连接都不会发生。

I need to retrive the exit status code from a command line program. No worries, I used $?. But for ftp, even if it doesn't connect, it opens the ftp shell, so I'm not able to understand that the connection haven't take place.

试试这个code表示理解:

Try this code for understand:

#!/bin/sh

ftp 1234567
OUT=$?
if [ $OUT -eq 0 ];then
   echo "ftp OK"
else
   echo "ftp Error: "$OUT
fi

exit 0

任何帮助吗?
感谢菲利普

Any help? Thanks Filippo

推荐答案

您应该寻找从ftp命令,而不是寻找一个状态成功消息。这是226传输完成。您可以与您的系统上FTP的手动确认。

You should be looking for success message from ftp command rather than looking for a status. It's "226 Transfer complete". You can confirm it with ftp manual on your system.

200 PORT command successful.
150 Opening ASCII mode data connection for filename.
226 Transfer complete.
189 bytes sent in 0.145 seconds (0.8078 Kbytes/s)

下面是一个示例脚本。

FTPLOG=/temp/ftplogfile
ftp -inv <<! > $FTPLOG
open server
user ftp pwd
put filename
close
quit
!

FTP_SUCCESS_MSG="226 Transfer complete"
if fgrep "$FTP_SUCCESS_MSG" $FTPLOG ;then
   echo "ftp OK"
else
   echo "ftp Error: "$OUT
fi
exit 0

这篇关于获取退出状态code从“FTP”命令在Linux的shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆