0

我正在尝试编写一个 shell 脚本,它从文本文件中获取一组参数,然后根据这些参数执行 SFTP。基本上,我正在获取每日网络统计日志并将其移动到中心位置。

我遇到的问题是 SFTP 基于我分配变量的方式而失败。我已经调试并发现while循环通过回显变量循环可以正常工作。我得到的错误是连接已关闭。

#!/bin/sh
source /home/ntadmin/webstats/bin/webstats.profile
source /home/ntadmin/webstats/bin/webstats.blogs.profile

DATE=`date +%m%d%Y`

SOURCE_FILE="`echo $WS_BC_SOURCE_FILE | sed -e 's/mmddyyyy/'$DATE'/'`"

IFS="," 
while read WS_BLOG_NAME WS_BLOG_SOURCE_VAR WS_BLOG_DEST_VAR WS_BC_SERVER1;
do


#Step 1 SFTP
cd $PERL_DIR
if $PERL_DIR/sftp.pl $WS_BC_SERVER1 $WS_BC_ID $WS_BC_PW $WS_BLOG_SOURCE_VAR/$SOURCE_FILE $WS_BLOG_DEST_VAR/$SOURCE_FILE
then
 echo 'SFTP complete'
else
 echo 'SFTP failed!'
 exit 1
fi

#Step 2 - Check that ftp was successful (that the files exist)
if [ -e $WS_BLOG_DEST_VAR/$SOURCE_FILE ]
then
echo "FTP of $WS_BLOG_SOURCE_VAR/$SOURCE_FILE from $WS_BC_SERVER1 was successful"
else
echo "FTP of $WS_BLOG_SOURCE_VAR/$SOURCE_FILE from $WS_BC_SERVER1 was not successful!"
exit 1
fi

done < blogs_array.txt
exit 0
4

1 回答 1

1

没有足够的信息来确定出了什么问题,但这里有一个调试方法。尝试用这样的调试脚本替换 perl 脚本中实际的 sftp 命令,您应该能够快速定位问题。

#!/usr/bin/perl
print "arguments passed to $0\n";
$i=0;
while (defined $ARGV[$i]) {
  print "arg ".($i+1)." is <$ARGV[$i++]>\n"
}
于 2012-04-05T21:33:56.257 回答