【问题标题】:Trying to run find command from a shell script in one server to another server尝试从一台服务器中的 shell 脚本运行 find 命令到另一台服务器
【发布时间】:2019-09-02 02:46:57
【问题描述】:

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

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

a.sh

#!/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

a.properties

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

但我最终得到以下错误 : Name or service not knownname a

其中 serverName 是我的服务器 a

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

【问题讨论】:

  • 您没有包含足够的代码来说明发生了什么。请edit您的问题包括所有相关代码。包括设置serverName 变量的代码。并确保您向我们展示了您正在运行的 ssh 命令的准确版本以及它产生的错误消息。不要转述这些东西。
  • @Kenster 我已经编辑了这个问题。我不能给出实际的服务器名称,但其余代码或多或少相同

标签: bash unix ssh find sh


【解决方案1】:

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

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

【讨论】:

  • 我尝试通过命令行运行相同的命令,然后它可以工作。
猜你喜欢
  • 2021-11-27
  • 2017-03-29
  • 1970-01-01
  • 2015-04-24
  • 2020-04-24
  • 1970-01-01
  • 2016-10-06
  • 1970-01-01
  • 2016-03-26
相关资源
最近更新 更多