从 linux shell 中的“ftp"命令获取退出状态码 [英] Getting exit status code from 'ftp' command in linux shell

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

问题描述

我需要从命令行程序中检索退出状态代码.不用担心,我用的是 $?.但是对于 ftp,即使没有连接,它也会打开 ftp shell,所以我无法理解连接没有发生.

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.

试试这个代码来理解:

#!/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

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

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