[工具] Shell 批量设置官方软件源 (openSUSE Leap 15.2 版)

介绍

基本信息

作者:朱明宇
名称:批量设置官方软件源(openSUSE 版)
作用:批量设置官方软件源(openSUSE 版)

使用方法

1. 服务器清单 $add_repo_servers_list.txt 每个服务器名占用 1 行,并和此脚本放在同一目录下
2. 在此脚本的分割线内写入相应的内容
3. 给此脚本添加执行权限
4. 执行此脚本

脚本分割线里的变量

add_repo_servers_list.txt #指定存放要设置官方软件源的文件

注意

1. 此脚本执行前必须要先保证执行此脚本的用户能无密码 ssh 远程这些远程服务器
2. 服务器的系统需要是 openSUSE 15.2 版本
3. 服务器系统要配置好可用的软件源(最好是软件数量最多的官方版本)
4. 这些远程服务器要能够连接外网

脚本

#!/bin/bash

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

add_repo_servers_list.txt

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

cat add_repo_servers_list.txt
read -p "will add opensuse_leap_15.2 repo please input y " a
echo $a

if [ "$a" != "y" ];then
        echo "you don't agree so exit now"
        exit
fi

for i in `awk '{print $1}' add_repo_servers_list.txt`
do
        ssh $i '
        sudo -u root su - root -c "zypper mr -da"
        sudo -u root su - root -c "zypper ar -fcg http://download.opensuse.org/distribution/leap/15.2/repo/oss/ OpenSUSE_Leap_152_x64_update-oss"
        sudo -u root su - root -c "zypper ar -fcg http://download.opensuse.org/distribution/leap/15.2/repo/non-oss/ OpenSUSE_Leap_152_x64_update-non-oss"
        sudo -u root su - root -c "zypper ar -fcg http://download.opensuse.org/update/leap/15.2/oss/ OpenSUSE_Leap_152_x64_oss"
        sudo -u root su - root -c "zypper ar -fcg http://download.opensuse.org/update/leap/15.2/non-oss/ OpenSUSE_Leap_152_x64_non-oss"
        sudo -u root su - root -c "zypper ref"
done

[工具] Shell 批量检测服务器 TCP 端口的联通状态 (nc 版)

介绍

基本信息

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

使用方法

1. 端口清单 $portlist 每 1 个端口占用 1 行,格式为:<IP address corresponding to the port number to be connected>:<port number to connect>:<port functions>
2. 在此脚本的分割线内写入相应的内容,并和此脚本放在同一目录下
3. 给此脚本添加执行权限
4. 执行此脚本,并将要测试的服务器 IP 地址跟在脚本的后面,例:. <script> <server IP address 1> <server IP address 2> ……

脚本分割线里的变量

portlist=tcp_ports.txt #存放要测试的 TCP 端口的文件

注意

1. 此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器
2. 执行此脚本前确保 nc 命令已经安装

脚本

#!/bin/bash

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

portlist=tcp_ports.txt

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

for hosts in $*
do

        echo $hosts
        ssh $hosts "which nc" &> /dev/null

        if [ $? -ne 0 ];then
                echo -e "\033[31m$hosts can not use nc !!!!!!!!!!\033[0m"
                continue
        fi

        for line in `cat $portlist`
        do
                ips=`echo $line | awk -F':' '{print $1}'`
                ports=`echo $line | awk -F':' '{print $2}'`
                remarks=`echo $line | awk -F':' '{print $3}'`

                ssh $hosts "nc -z -w 3 $ips $ports"

                if [ $? -ne 0 ];then
                        echo -e "\033[31m$ips $ports $remarks can not be connected !!!!!!!!!!\033[0m"
                else
                        echo -e "\033[32m$ips $ports $remarks can be connected\033[0m"
                fi

        done

done

[工具] 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