[工具] Shell 批量比较服务器所有正在运行进程的变化

介绍:

作者:朱明宇
名称:批量比较服务器所有正在运行进程的变化
作用:批量比较服务器所有正在运行进程的变化

使用方法:
1. 服务器清单 $server_list 每一台服务器占用一行
2. 在此脚本的分割线内写入相应的内容,并和此脚本放在同一目录下
3. 给此脚本添加执行权限
4. 执行此脚本
5. 此脚本执行完成后,会将运行结果写入当前目录下的 $compare_file 里

脚本分割线里的变量:
server_list=server_list.txt #服务器清单
first_time=first_time #存储第一次检结果的目录
second_time=second_time #存储第二次检查结果的目录
compare_file=comparison_results.txt #存储比较结果的文件

注意:
此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器

脚本:

#!/bin/bash

####################### Separator ########################

server_list=server_list.txt
first_time=first_time
second_time=second_time
compare_file=comparison_results.txt

####################### Separator ########################

mkdir $first_time &> /dev/null
mkdir $second_time &> /dev/null
echo > $compare_file

read -p "Please input first second or compare now: " choice

check(){
        for server_name in `cat $1`
        do
                ssh -t $server_name "ps -A" | awk '{print $4}' > $2/$server_name
        done
}

compare(){
        for server_name in `cat $1`
        do
                echo $server_name >> $4
                for process in `cat $2/$server_name`
                        do
                        grep $process $3/$server_name &> /dev/null
                        if [ $? -ne 0 ];then
                                echo $process >> $4
                        fi
                done
                echo >> $4
        done
}

if [ $choice == first ];then
        check $server_list $first_time
fi

if [ $choice == second ];then
        check $server_list $second_time
fi

if [ $choice == compare ];then
        compare $server_list $first_time $second_time $compare_file
fi

[STEP] Red Hat Satellite client register

Step One: Add domain name resolution into /etc/hosts

# vim /etc/hosts

Add the following:

......
<Redhat Satellite IP address> <Redhat Satellite Server FQDN>

Step Two: Install katello-ca-consumer-latest.noarch.rpm
2.1 Download katello-ca-consumer-latest.noarch.rpm

# curl --insecure --output katello-ca-consumer-latest.noarch.rpm https://<Redhat Satellite Server FQDN>/pub/katello-ca-consumer-latest.noarch.rpm

2.2 Install katello-ca-consumer-latest.noarch.rpm

# yum -y localinstall katello-ca-consumer-latest.noarch.rpm

Step Three: Register to Red Hat Satellite Server

# subscription-manager register --org="<organization>" --activationkey="<activation key>"

Step Four: Install katello-host-tools, katello-host-tools-tracer and katello-agent
4.1 Enable rhel-*-satellite-tools-*-rpms repo or satellite-tools-*-rhel-*-rpms
4.1.1 For RHEL 7

# subscription-manager repos --enable=rhel-\*-satellite-tools-\*-rpms

4.1.2 For RHEL 8

# subscription-manager repos --enable=satellite-tools-\*-rhel-\*-rpms
# subscription-manager repos --disable=satellite-tools-\*-rhel-\*-eus-rpms

4.2 Install katello-host-tools, katello-host-tools-tracer and katello-agent

# yum -y install katello-host-tools; yum -y install katello-host-tools-tracer; yum -y install katello-agent

Step Five: Check
5.1 Check registration information

# subscription-manager identity

5.2 Check license

# subscription-manager list --consumed

盾牌和铠甲

在用经验拼凑的盾牌上
扎满了纷乱错综的谎言
在用梦想打造的铠甲上
布满了恶毒欺诈的伤痕

在战火之中的坚持
在孤独尽头的珍视
该相信什么是唯一的希望
该决定什么是生命绝对不应该如此

梦想之上的梦想
逆风而上的飞翔
判断之后的判断
逆光而向的洞察

过去无意间犯下的错误
就算会辗转反侧悔恨终身
也绝不会为了内心安稳而放弃的那份善念
将会成为人们在这颗星球上最后的盾牌

理想之上的理想
不会后悔的牺牲
选择之后的选择
不会后怕的勇敢

如今必须要去面对的那些邪恶
就算会因毫无安全感而变得焦躁不安
也绝不会为了内心安稳而抛弃的那份公正
将会成为人们在这颗星球上最后的铠甲

稍纵即逝的人生
生命的价值从来都不是曾存在于世
共同理想的创造
人类会因为拥有彼此而变得无所畏惧