2017-10-16 92 views
0

我从远程计算机使用SFTP复制一些文件到我的机器:比较文件大小从远程计算机上的bash

ssh [email protected]_host ' 
find /file/location -type f -maxdepth 1 -size +400000c -name "TEXT_*" 
'>> log 

cat log | while read line; do 

sftp [email protected]_host <<EOF 
get $line 
EOF 

done 

rm log 

我想现在要做的是检查,如果复制的文件的文件大小是与远程机器上的文件相同。这是我的尝试:

ls -1 TEXT* | while read line; 
do var=$(stat "/file/on/current/machine/$line"); 
    var2=`ssh -n [email protected]_host 'ls -l /file/on/remote/$line | cut -d " " -f5 '`; 
     if [ "$var" == "$var2" ]; 
     then 
       echo "The file $line has the same dimension!"; 
     else 
       echo "The file $line doesn't have the same dimension"; 
     fi; 
done 

的问题是变量$行不会ssh命令里面的认可,并将其返回远程主机上的所有文件,不仅已复制的那些的大小。

谢谢!

回答

1

这是因为$line在单引号内。变量只能用双引号插入。

var2=$(ssh -n [email protected]_host "ls -l /file/on/remote/$line | cut -d ' ' -f5 ")