从本地服务器执行时,Unix命令在远程服务器中不起作用吗?

时间:2018-07-25 09:18:43

标签: shell unix

我有文件test2.txt,其中包含远程服务器中存在的文件的名称。但是,我已将此脚本与文件test2.txt一起放置在本地服务器中。 我想在本地服务器上执行此脚本,以查找text2.txt中提到的文件是否存在于远程服务器中。如果存在,我想搬家 它们位于远程服务器本身的特定目录中。但是,在与远程服务器建立连接后,即之后,此代码在远程服务器中不起作用 为我在$(ssh -q -o“ StrictHostKeyChecking no” username @ hostname cat apps / dir / test2.txt);

下面是代码段

#!/bin/bash
for i in $(ssh -q -o "StrictHostKeyChecking no" username@hostname cat apps/dir/test2.txt);
do
if [ ! -d $BACKUP ]; then
    mkdir BACKUP
fi
file_exists=find /apps/dir/ -type f -name "$i"  -print
cp apps/dir/$file_exists BACKUP
echo "The path is: $file_exists"
done

0 个答案:

没有答案