比较两个目录内的同名文件(后缀yml,xml的文件)的非空行数是否一致
chatgpt确实好用,比自己吭哧吭哧google快多了
#脚本所在目录
rootDir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# 输出服务器ip
echo "--- $(hostname -i): $rootDir ---"
dir1=$rootDir/old
dir2=$rootDir/new
find $dir1 -type f | while read file; do
filename=${file#$dir1}
if [ -e $dir2/$filename ]; then
count1=$(grep -cve '^\s*$' $file)
count2=$(grep -cve '^\s*$' $dir2/$filename)
if [ $count1 -ne $count2 ]; then
echo "NG ${filename} 非空行数不一致 old-${count1} : new-${count2}"
else
echo "OK ${filename}"
fi
fi
done
ssh执行远程服务器上的脚本
# 生成ssh密钥
ssh-keygen
# 连接目标服务器
ssh-copy-id userid@hostname
# 上一步登陆成功后即可执行
ssh user@remote-server /path/to/script.sh
Updated: 2023-04-29 23:41
Created: 2023-04-24 21:02