[工具] Shell 显示可以无密码登陆系统的用户

脚本:

作者:朱明宇
名称:显示可以无密码登陆系统的用户
作用:显示可以无密码登陆系统的用户

使用方法:
1. 给此脚本添加执行权限
2. 执行此脚本

介绍:

#!/bin/bash

for name in `egrep '^.*\:!!\:.*$|^.*\:\*\:.*$' /etc/shadow | cut -d : -f 1`
do
        egrep '/sbin/nologin|/bin/false' /etc/passwd | egrep $name > /dev/null

        if [ $? -ne 0 ];then
                envi=`grep $name /etc/passwd | cut -d : -f 7`
                echo "$name has no password but maybe can access system, it is $envi"
        fi

done

[工具] Shell 检测服务器 SSH 端口的联通状态

介绍

#作者:朱明宇
#名称:检测服务器 SSH 端口的联通状态
#作用:检测服务器 SSH 端口的联通状态

#使用方法:
#1. 在此脚本的分割线内写入相应的内容
#2. 给此脚本添加执行权限
#3. 执行此脚本
#4. 如果联通检测失败则会将结果写入脚本同目录下的 checkserver.txt

脚本分割线里的变量:
host=”8.8.8.8″ #需要检测 SSH 端口联通性的服务器 IP 地址

脚本:

#!/bin/bash

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

host="8.8.8.8"

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

checktime=`date +%Y-%m-%d-%H-%M`
sleep 2 | telnet $host 22 | grep SSH

if [ $? -ne 0 ];then
	echo "$checktime server timeout" >> checkserver.txt
fi

[工具] Shell 批量检测某一个软件包的安装情况 (通过读取和生成 CSV 文件实现)

介绍:

使用方法:
1. 将此脚本和 patch.cs 文件放在同一目录下
2. patch.cs 里每一个 IP 地址和每一个 RPM 包名称占用一行
3. 给此脚本添加执行权限
4. 执行此脚本
5. 此脚本执行完成后,会将运行结果写入当前目录下的 checkout.csv 里

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

补充:patch.cs 示例如下:

192.168.100.101,kernel-4.18.0-80.el8.x86_64,other0
192.168.100.102,kernel-4.18.0-80.el8.x86_64,other1
192.168.100.103,kernel-4.11.0-80.el8.x86_64,other2
192.168.100.104,kernel-4.18.0-80.el8.x86_64,other3
192.168.100.105,kernel-4.18.0-80.el8.x86_64,other4

脚本:

#!/bin/bash

for i in `seq 1 $(cat patch.csv | wc -l)`
do

        servername=`sed -n "$[i]p" patch.csv | cut -d ',' -f 1`
        software=`sed -n "$[i]p" patch.csv | cut -d ',' -f 2`

        ssh $servername "rpm -qa | grep $software" &> /dev/null

        if [ $? -eq 0 ];then
                echo "$servername,$software,have not patched"
        else
                echo "$servername,$software,have patched"
        fi

done

[工具] Shell 显示使用 swap 的进程

介绍:

作者:朱明宇
名称:显示使用 swap 的进程
作用:显示使用 swap 的进程

使用方法:
1. 给此脚本添加执行权限
2. 执行此脚本
3. 执行结果会输出到脚本同目录下的 swapcheck.txt 目录中

脚本:

#!/bin/bash

echo > swapcheck.txt

for pid in `ls /proc/ | egrep ^[0-9] | awk '$0 > 100'`
do 

        ls /proc/$pid &> /dev/null
        
        if [ $? -ne 0 ];then
                continue
        fi

        size=`awk '/Swap:/{a=a+$2}END{print a}' /proc/$pid/smaps` 
        name=`ps -aux | egrep $pid`

        if [ -z $size ];then
                continue
        fi

        if [ $size -eq 0 ];then
                continue
        fi

        echo "$[size]k $pid \"$name\"" >> swapcheck.txt
        echo  >> swapcheck.txt

done