【发布时间】:2011-07-30 02:48:27
【问题描述】:
我有大量使用以下函数的脚本:
# Copies files over using FTP.
# Configurations set at the beggining of the script
# @param $1 = FTP Host
# $2 = FTP User
# $3 = FTP User password
# $4 = Source file name
# $5 = destination directory
# $6 = local directory
doftp() {
log_message_file "INFO" "Starting FTP"
ftp_hst=$1
ftp_usr=$2
ftp_pwd=$3
sourcefile=$4
destdir=$5
locdir=$6
ftp -nv $FTPH << EOF 2> ftp.err.$$
quote USER $ftp_usr
quote PASS $ftp_pwd
cd $destdir
lcd $locdir
bin
put $sourcefile
bye
EOF
if [ "$(wc ftp.err.$$|cut -d" " -f8)" != 0 ] ; then
log_message_file "ERROR" "Problem uploading files: $(cat ftp.err.$$)"
else
log_message_file "INFO" "FTP finished"
fi
rm ftp.err.$$
}
它工作,它的工作,除非 ftp 失败。对我来说幸运的是,脚本非常精确,FTP 几乎从不失败。但这是难得的时刻之一,人们有机会(时间)返回并查看 TODO 列表中标记的代码。唯一的问题是我不太确定如何改进它......我会向你们提出关于在那里改变什么的建议。
一个明显的问题是从 ftp 解析错误,这完全是蹩脚的。但我也会考虑函数的其他部分:)
值得一提的是这是在 AIX 服务器上运行的吗?哦,不,我不能使用 SFTP :(
感谢您的任何意见!
ps.:log_message_file 只是一个基本的日志记录...对功能没有影响。
【问题讨论】:
-
也许这更适合 codereview.stackexchange.com
-
您使用哪种外壳?例如对于 ksh 和 bash,
$(< filename)可以替换$(cat filename) -
谢谢!是克什。但改变真的值得吗?我的意思是,我猜
cat让它更跨平台,对吧?