答案1
这个答案是来自 OP 的请求(有关详细信息,请参阅 OP 问题的评论),要求收集已安装软件包的脚本。
请记住,以下脚本适用于 RHEL(Red Hat Enterprise Linux),如果您运行的是不同的系统,您仍然可以通过更新特定的包管理器命令以匹配您的系统来使用它。
#!/bin/bash
# VARS
# declare the hostnames of your servers. it requires to have a config file inside ./ssh with the connection information.
HOSTS=" prd_webserver1 prd_webserver2 prd_db1 prd_db2 prd_frontend1 prd_frontend2"
# create a store directory on the path were the script is
store="artifact_store"
# declare roles based on hostname
role_store="webserver db frontend"
# Create artifact_store directory
[ ! -d "$store" ] && mkdir -p "$store"
# Create role store directories
for ROLE_DIR in ${role_store}; do
[ ! -d "$store/${ROLE_DIR}" ] && mkdir -p "$store/${ROLE_DIR}"
done
CMDS=$(cat <<CMD
bash -c "sudo yum -q check-update --security --exclude=kernel* |awk '{print $ 1}' > /tmp/updatelist.log"
CMD
)
# Create update lists
for HOSTNAME in ${HOSTS}; do
ssh -t ${HOSTNAME} "$CMDS"
scp ${HOSTNAME}:/tmp/updatelist.log ./updatelist_${HOSTNAME}.log
mv updatelist_${HOSTNAME}.log $store
done
# Create role directories and move artifacts
for ROLE in ${role_store}; do
mv $store/*${ROLE}*.log $store/${ROLE}
cat $store/${ROLE}/updatelist_*.log >> $store/${ROLE}/updatelist.combined
cat $store/${ROLE}/updatelist.combined |sort |uniq >> $store/${ROLE}/updatelist.final
rm $store/${ROLE}/updatelist.combined
done