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

介绍

基本信息

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

使用方法

1. 服务器清单 $server_list 每台服务器占用 1 行
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

[工具] Shell LNMP 没运行则重启系统 (systemctl 版)

介绍

基本信息

作者:朱明宇
名称:LNMP 没运行则重启系统
作用:LNMP 没运行则重启系统

使用方法

1. 在此脚本的分割线内写入相应的内容
2. 给此脚本添加执行权限
3. 执行此脚本

脚本

#!/bin/bash
  
systemctl status nginx | grep 'active (running)'
if [ $? -ne 0 ];then
        /usr/sbin/reboot
fi

systemctl status mariadb | grep 'active (running)'
if [ $? -ne 0 ];then
        /usr/sbin/reboot
fi

systemctl status php-fpm | grep 'active (running)'
if [ $? -ne 0 ];then
        /usr/sbin/reboot
fi

[工具] Shell 显示所有可升级的软件版本,并自动生成相应的升级命令 (openSUSE & SLE)

介绍

基本信息

作者:朱明宇
名称:openSUSE & SLE 显示所有可升级的软件版本,并自动生成相应的升级命令
作用:openSUSE & SLE 显示所有可升级的软件版本,并自动生成相应的升级命令

使用方法

给此脚本添加执行权限
执行此脚本
执行此脚本大致会生成以下内容:

zypper update  MozillaFirefox-78.12.0-lp152.2.61.1 MozillaFirefox-translations-common-78.12.0-lp152.2.61.1 alsa-oss-1.1.8-lp152.4.3.1

脚本

#!/bin/bash

m=''

for n in `zypper list-updates | tail -n +5 | awk '{print $7"-"$11}'`
do
        m="$m $n"
done

echo "zypper update $m"