【发布时间】: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 我已经编辑了这个问题。我不能给出实际的服务器名称,但其余代码或多或少相同