尝试从一个服务器中的shell脚本运行find命令到另一个服务器

问题描述 投票:-1回答:1

我在服务器A中有一个shell脚本,它有一个find命令在另一台服务器B中执行。我该怎么做?

我像这样运行我的脚本:./ a.sh a.properties

啊.是

#!/bin/sh

file="$1"
echo 'Reading file ' $file

if [ -f "$file" ]
then
        echo "Sourcing the file $file"
        . $file
else
        echo "$file not found. Quitting Script"
        exit 1
fi

for serverName in $allServerList
do
        for cleanupPath in $cleanupPathList
        do
                ssh a_io@$serverName -t "find $cleanupPath -type f ! -regex $excludeFileList -mtime -120 -mtime +30 | zip -@ $1/$(date +%Y%m%d).logs.backup.zip"
                ssh a_io@$serverName "find $cleanupPath -type f ! -regex $excludeFileList -mtime +30 -delete"
        done
done

啊.properties

cleanupPathList="/tmp/abc/"
excludeFileList=".*\(.xlsx.*\|.ktr.*\)$"
SERVER1="a"
#SERVER2="b"
allServerList="$SERVER1"

但我最终得到以下错误:名称或服务未知名称a

serverName是我的服务器a

注意:我尝试通过命令行运行相同的命令,然后它工作。

bash unix ssh find sh
1个回答
0
投票

您的变量serverName不存在,或变量中的域未解析。

如果是域,请尝试解析它以检查IP host $serverName

© www.soinside.com 2019 - 2024. All rights reserved.