shell命令在SFTP脚本中不起作用

shell命令在SFTP脚本中不起作用,shell,sftp,Shell,Sftp,我是编程新手。。我有这个sftp脚本,它将sftp发送到另一个服务器,检查一些条件,然后获取文件 #! /usr/bin/bash while read line do #echo $line if [[ $line =~ ^# ]]; then #echo $line; continue; else serverIP=`echo $line|cut -d',' -f1` userID=`echo $line|cut -d',' -f2` fi done < sftp.conf c

我是编程新手。。我有这个sftp脚本,它将sftp发送到另一个服务器,检查一些条件,然后获取文件

#! /usr/bin/bash

while read line
do
#echo $line
if [[ $line =~ ^#  ]];
then
#echo $line;
continue;

else
serverIP=`echo $line|cut -d',' -f1`
userID=`echo $line|cut -d',' -f2`
fi
done < sftp.conf

cd /root

sshpass -p red32hat sftp $userID@$serverIP <<EOF
for (; ;) 
do
cd /root/perl
#foreach my $file (<$inputdir/*seq>) {
for $file in *seq 
do
abc1=`find $file -mmin +1`;
if [[ $abc1 eq "" ]] 
then
echo "Skipping file as of now as file is not completed \n";
continue;
fi
mget $file
done
sleep 30
done
bye
EOF
但它会在每个sftp步骤中抛出错误,表示命令无效。。我猜通用shell命令在sftp中不起作用。。。请帮助…下面是错误消息

eankuls@L9AHR43:~/Idea_Expan$ bash -x sftp_idea.sh
+ read line
+ [[ #bsackjsabckjdsbcds =~ ^# ]]
+ continue
+ read line
+ [[ rinacac-test,root =~ ^# ]]
++ echo rinacac-test,root
++ cut -d, -f1
+ serverIP=rinacac-test
++ echo rinacac-test,root
++ cut -d, -f2
+ userID=root
+ read line
+ [[ #geet =~ ^# ]]
+ continue
+ read line
+ sshpass -p red32hat sftp root@rinacac-test

    ------------------------------------------------------------------------------------
    These computer resources, specifically Internet access and E-mail, are
    provided for authorized users only. 

    IF YOU ARE NOT AN AUTHORIZED USER, PLEASE EXIT IMMEDIATELY.
    ------------------------------------------------------------------------------------
Connected to rinacac-test.
sftp> for ((;;)) 
Invalid command.
sftp> do
Invalid command.
sftp> cd /root/perl
sftp> #foreach my $file (<$inputdir/*seq>) {
sftp> for file in *seq 
Invalid command.
sftp> do
Invalid command.
sftp> abc1=`find $file -mmin +1`;
Invalid command.
sftp> if [[ $abc1 == "" ]]
Invalid command.
sftp> then
Invalid command.
sftp> echo "Skipping file as of now as file is not completed \n";
Invalid command.
sftp> continue;
Invalid command.
sftp> fi
Invalid command.
sftp> mget $file
Couldn't stat remote file: No such file or directory
File "/root/perl/$file" not found.
sftp> done
Invalid command.
sftp> sleep 30
Invalid command.
sftp> done
Invalid command.
sftp> bye

向EOF添加报价,以防止在此文档中进行扩展:

sshpass -p red32hat sftp "$userID@$serverIP" <<'EOF'
并在引号周围放置变量,以防止分词和路径名扩展

同样,对于*seq中的$file,也应该是对于*seq中的file

为了;也应该是为


[$abc1 eq]]中的eq不是有效的运算符。可能您的平均值=或=。

我想您没有安装sftp。请使用sudo-apt-get-install-openssh-serverHi安装…我的系统上安装了sftp。。如果我只使用mget命令,它的工作很好。。我想问题在于我在sftp中使用的其他命令…谢谢…嗨。。。我试过了…但是对于这里的每个命令,博士。这是一个无效的命令。。。比如:sftp>then;无效的命令..谢谢你应该通过编辑你的文章来提供更多的细节这些问题是如何发生的。尝试运行bash-x your_script.sh并在帖子上显示所有消息,而不是在此处显示评论。您好。。我已经在帖子中包含了错误代码。。再一次-x在sftp内不工作…谢谢…@Geetika很明显我没有注意到。您正在将shellsript命令传递给sftp,因此它自然会显示错误,因为这些命令对它无效。我对ftp或sftp不太了解。您可以做的最好的事情是参考有关其命令的有效文档,并根据它修复代码。我能帮助的最好的事情就是修复shell语法。