#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-17
#FileName: system_info_1.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
RED="\E[1;31m"
GREEN="echo -e \E[1;32m"
END="\E[0m"
$GREEN-----------------------Host systeminfo----------------------------------$END
echo -e "HOSTNAME: $RED`hostname`$END"
echo -e "IPADDR: $RED`ifconfig eth0|grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' |head -n1`$END"
echo -e "OSVERSION: $RED`cat /etc/redhat-release`$END"
echo -e "KERNEL: $RED`uname -r`$END"
echo -e "CPU: $RED`lscpu|grep 'Model name'|tr -s ' '|cut -d : -f2`$END"
echo -e "MEMORY: $RED`free -h|grep Mem|tr -s ' ' : |cut -d : -f2`$END"
echo -e "DISK: $RED`lsblk|grep '^sd'|tr -s ' '|cut -d " " -f4`$END"
$GREEN------------------------------------------------------------------------$END
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-17
#FileName: backup2.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
COLOR='echo -e \E[1;35m'
END='\E[0m'
BACKUP=/backup
SRC=/etc
DATE=`date +%F`
mkdir -p ${BACKUP}
${COLOR}Starting backup...$END
sleep 2
cp -av $SRC ${BACKUP}${SRC}_$DATE
${COLOR}Backup is finished$END
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-17
#FileName: disk.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
GREEN="echo -e \E[1;33m"
END="\E[0m"
${GREEN}`df | grep "^/dev/sd" |grep -Eo [0-9]+%|cut -d% -f1|sort -nr|head -1`${END}
序
BEGIN="\e[1;32m"
END="\e[0m"
echo -e ${BEGIN}`ss -tan |grep "ESTAB"|tr -s " " :|cut -d: -f6|sort|uniq -c |sort -nr`${END}
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-21
#FileName: argsnum.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
if [ $# -lt 1 ];then
echo "至少应该给一个参数"
exit
elif [ -f $1 ];then
grep "^$" $1 |wc -l
else
echo "请输入有效文件路径"
fi
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-21
#FileName: hostping.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
read -p "Please input IP address: " IP
ping -c1 -W1 $IP &> /dev/null && echo "该$IP地址可访问" || echo "该$IP地址不可访问"
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-21
#FileName: checkdisk.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
WARNING=1
SPACE_USE=`df|sed -nr '/^\/dev\/sd/ s@^.* ([0-9]+)%.*@\1@p'|sort -nr |head -1`
INODE_USE=`df -i|sed -nr '/^\/dev\/sd/ s@^.* ([0-9]+)%.*@\1@p'|sort -nr |head -1` [ $SPACE_USE -gt $WARNING -o $INODE_USE -gt $WARNING ] && wall disk_space is fulled
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-21
#FileName: per.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
[ ! -r $1 -a ! -w $1 ] && echo "不可读且不可写"
read -p "请输入文件: " file
if [ ! -r $file -a ! -w $file ] ; then
echo "不可读且不可写"
fi
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-21
#FileName: excute.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
read -p "请输入参数文件:" FILE
[ -f $FILE ] && [[ $FILE == *.sh ]] && chmod +x $FILE; echo 已经添加执行权限 || echo "这不是脚本文件"
read -p "Please input a filename: " file
if [[ $file =~ .*sh$ ]] ; then
if [ -f $file ] ; then
chmod a+x $file
echo "success"
fi
else
echo '非脚本文件'
fi
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-21
#FileName: nologin.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
[ -f /etc/nologin ] && echo "已禁止普通用户登录" || { touch /etc/nologin;echo "已开启禁止普通用户登录"; }
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-21
#FileName: login.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
[ -f /etc/nologin ] && { rm -rf /etc/nologin;echo "已开启普通用户登录"; } || echo "已允许普通用户登录"
cdnet=‘cd /etc/sysconfig/network-scripts/’
editnet=‘vim /etc/sysconfig/network-scripts/ifcfg-eth0’
editnet=‘vim /etc/sysconfig/network-scripts/ifcfg-eno16777736 或 ifcfg-ens33 ’ (如果系统是
CentOS7)
echo "PATH=$PATH:/usr/local/apache/bin" >> /etc/profile.d/path.sh
vim /root/.bashrc
PS1="\[\e[0;31m[\u@\h \W]\\$\e[0m\]"
alias rm='rm –i'
alias cdnet='cd /etc/sysconfig/network-scripts/'
alias editnet='vim /etc/sysconfig/network-scripts/ifcfg-eth0'
alias editnet='vim /etc/sysconfig/network-scripts/ifcfg-ens33'
[root@CentOS8-minal ~]# echo 'echo -e "\e[1;31mHi,dangerous! \e[0m"' > /etc/prodfile.d/start.sh
vim .vimrc
set ignorecase
set cursorline
set autoindent
set expandtab
set ts=4
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
if expand("%:e") == 'sh'
call setline(1,"#!/bin/bash")
call setline(2,"#")
call setline(3,"#********************************************************************")
call setline(4,"#Author: wangmingwang")
call setline(5,"#QQ: 2380821650")
call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileName: ".expand("%"))
call setline(8,"#URL: http://www.wangmingwang.com")
call setline(9,"#Description: The test script")
call setline(10,"#Copyright (C): ".strftime("%Y")." All rights reserved")
call setline(11,"#********************************************************************")
call setline(12,"")
endif
endfunc
autocmd BufNewFile * normal G
#********************************************************************
read -p "请输入身高(m为单位): " HIGH
if [[ ! $HIGH =~ ^[0-2](\.[0-9]{,2})?$ ]];then
echo "输入错误的身高"
exit 1
fi
read -p "请输入体重(kg为单位) " WEIGHT
if [[ ! "$WEIGHT" =~ ^[0-9]{1,3}$ ]];then
echo "输入错误的身高"
exit 1
fi
BMI=`echo $WEIGHT/$HIGH^2|bc`
if [ $BMI -le 18 ];then
echo "太瘦了,多吃点"
elif [ $BMI -lt 24 ];then
echo "身材很棒!"
else
echo "太胖了,注意节食,加强运动"
fi
版本1:
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-21
#FileName: createuser.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
#定义变量
read -p "Please input Username: " username
#判断用户名是否存在
if [ -z $username ];then
echo "请输入用户名: "
exit 2
elif `id $username &> /dev/null`;then
echo "$username is exited"
else
#如果不存在,添加用户 设置密码 下次登陆时修改密码 同时显示ID等信息
PASSWORD=`cat /dev/urandom |tr -dc [:alpha:] |head -c8`
`useradd $username &> /dev/null`
`echo $PASSWORD |passwd --stdin $username &> /dev/null`
echo "用户名:$username 密码: $PASSWORD" >> user.txt
`chage -d 0 $username`
echo "用户已添加,用户的ID信息为:`id $username` 密码为: $PASSWORD"
版本2:
#!/bin/bash
read -p "Please input a username: " NAME
if [ -z $NAME ];then
echo -e "\e[1;37mInput a username.\e[0m"
exit 2
fi
if getent passwd $NAME;then
echo -e "\e[1;32m$NAME is exist.\e[0m"
else
useradd $NAME
echo $NAME:123456 | chpasswd $NAME
id $NAME
passwd -e $NAME &> /dev/null
fi
版本1 :
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: yesorno.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
read -p "Please input yes or no : " answer
answer=`echo $answer |tr 'A-Z' 'a-z'`
case $answer in
y|yes)
echo "your input is YES"
;;
n|no)
echo "your input is NO"
;;
*)
echo "input fales,please input yes or no!"
esac
版本2 :
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: case_yesorno2.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
read -p "Please input yes or no : " answer
case $answer in
[yY]|[yY][Ee][sS])
echo "You input is YES"
;;
[Nn]|[Nn][Oo])
echo "You insput is NO"
;;
*)
echo "You input false,Please input yes or no !"
esac
read -p "Please input a filename: " FILE
TYPE=`ls -ld $FILE|grep -Eo '^.'`
case $TYPE in
-)
echo -e "\E[1;31m$FILE is a nomal file\E[0m"
;;
d)
echo -e "\E[1;32m$FILE is a directory file\E[0m"
;;
l)
echo -e "\E[1;33m$FILE is a link file\E[0m"
;;
b)
echo -e "\E[1;34m$FILE is a block file\E[0m"
;;
c)
echo -e "\E[1;35m$FILE is a character file\E[0m"
;;
s)
echo -e "\E[1;36m$FILE is a socket file\E[0m"
;;
p)
echo -e "\E[1;37m$FILE is a pipe file\E[0m"
;;
*)
echo -e "\E[1;31m$FILE is other type file\E[0m"
esac
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: checkint.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
read -p "Please input a digit: " NUM
[[ $NUM =~ ^[0-9]+$ ]] && echo -e "\E[1;32m$NUM is a positive integer\E[0m" || echo -e "\E[1;31m$NUM is not a positive integer\E[0m"
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: reset_centos.sh
#URL: www.wangmingwang.com
#Description: The Centos reset script
#Copyright (C): 2021 All rights reserved
#********************************************************************
. /etc/init.d/functions
centos_version() {
sed -rn 's#^.* ([0-9]+)\..*#\1#p' /etc/redhat-release
}
disable_selinux(){
sed -ri.bak 's/^(SELINUX=).*/\1disabled/' /etc/selinux/config
action "CentOS`centos_version`SELinux已禁用,请重新启动系统后才能生效!"
}
set_alias(){
cat >>~/.bashrc <~/.vimrc <~/.mailrc < /dev/null
action "CentOS`centos_version`防火墙已关闭!"
}
disable_firewalld_centos6(){
chkconfig iptables off
action "CentOS`centos_version`防火墙已关闭!"
}
disable_firewalld(){
centos_version | while read ov ;do
if [ $ov -eq 6 ];then
disable_firewalld_centos6
else
disable_firewalld_centos78
fi
done
}
set_yum_centos8(){
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > /etc/yum.repos.d/base.repo < /etc/yum.repos.d/base.repo < /etc/yum.repos.d/base.repo <& /dev/null
#修改网卡文件名
mv /etc/sysconfig/network-scripts/ifcfg-${ETHNAME} /etc/sysconfig/network-scripts/ifcfg-eth0
action "CentOS`centos_version`网卡名已修改成功,请重新启动系统后才能生效!"
}
check_ip(){
local IP=$1
VALID_CHECK=$(echo $IP|awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}')
if echo $IP|grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null; then
if [ $VALID_CHECK == "yes" ]; then
echo "IP $IP available!"
return 0
else
echo "IP $IP not available!"
return 1
fi
else
echo "IP format error!"
return 1
fi
}
set_ip(){
while true; do
read -p "请输入IP地址:" IP
check_ip $IP
[ $? -eq 0 ] && break
done
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 < /etc/profile.d/env.sh
$TIPS
;;
2)
echo "PS1='\[\e[1;32m\][\u@\h \W]\\$ \[\e[0m\]'" > /etc/profile.d/env.sh
$TIPS
;;
3)
echo "PS1='\[\e[1;33m\][\u@\h \W]\\$ \[\e[0m\]'" > /etc/profile.d/env.sh
$TIPS
;;
4)
echo "PS1='\[\e[1;34m\][\u@\h \W]\\$ \[\e[0m\]'" > /etc/profile.d/env.sh
$TIPS
;;
5)
echo "PS1='\[\e[1;35m\][\u@\h \W]\\$ \[\e[0m\]'" > /etc/profile.d/env.sh
$TIPS
;;
6)
echo "PS1='\[\e[1;36m\][\u@\h \W]\\$ \[\e[0m\]'" > /etc/profile.d/env.sh
$TIPS
;;
7)
echo "PS1='\[\e[1;"$[RANDOM%7+31]"m\][\u@\h \W]\\$ \[\e[0m\]'" > /etc/profile.d/env.sh
$TIPS
;;
8)
break
;;
*)
echo -e "\e[1;31m输入错误,请输入正确的数字(1-8)!\e[0m"
;;
esac
done
}
PS3="请选择相应的编号(1-13):"
MENU="
CentOS禁用SELinux
CentOS设置系统别名
CentOS设置vimrc配置文件
CentOS设置mailrc配置文件
CentOS关闭防火墙
CentOS设置YUM源
CentOS_Minimal安装建议安装软件
CentOS1-7全执行
CentOS修改网卡名和IP地址
CentOS设置主机名
CentOS设置PS1(请进入选择颜色)
重启系统
退出
"
select menu in $MENU;do
case $REPLY in
1)
disable_selinux
;;
2)
set_alias
;;
3)
set_vimrc
;;
4)
set_mailrc
;;
5)
disable_firewalld
;;
6)
set_yum
;;
7)
centos_minimal_install
;;
8)
disable_selinux
set_alias
set_vimrc
set_mailrc
disable_firewalld
set_yum
centos_minimal_install
;;
9)
set_eth_ip
;;
10)
set_hostname
;;
11)
set_centosps1
;;
12)
reboot
;;
13)
break
;;
*)
echo -e "\e[1;31m输入错误,请输入正确的数字(1-13)!\e[0m"
;;
esac
done
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: 9x9.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
#版本1:
for j in {1..9}; do
for i in `seq $j` ;do
echo -e "\E[1;$[RANDOM%7+31]m${i}x${j}=$[i*j]\E[0m\t\c"
done
echo
done
echo
#版本2:
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: 9x9_for.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
语句1:
for i in {1..9};do
for j in `seq $i`; do
echo -e "${j}x${i}=$[j*i]\t\c"
done
echo
done
echo
语句2:
for ((i=1;i<10;i++));do
for ((j=1;j<=i;j++));do
echo -e "${j}x${i}=$((j*i))\t\c"
done
echo
done
for ((i=1;i<=9;i++));do
for ((j=1;j<=i;j++));do
printf "\E[1;$[RANDOM%7+31]m${i}x${j}=$[i*j]\E[0m\t"
done
printf "\n"
done
[root@WMW-CentOS8 scripts]# cat 9x9_2.sh
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: 9x9_2.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
for i in {1..9}; do
for j in $(seq `echo $[10-$i]`);do
echo -ne "${j}x`echo $[10-i]`=$(((10-i)*j))\t"
done
echo
done
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: for_rename.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
DIR=/data/test
cd $DIR || { echo 无法进入 $DIR ;exit 1; }
for FILE in * ;do
# PRE=`echo $FILE|grep -Eo ".*\."`
# mv $FILE ${PRE}bak
# PRE=`echo $FILE|rev |cut -d. -f 2-|rev`
PRE=`echo $FILE|sed -nr 's/(.*)\.([^.]+)$/\1/p'`
SUFFIX=`echo $FILE|sed -nr 's/(.*)\.([^.]+)$/\2/p'`
mv $FILE $PRE.bak
done
1、先创建Y-M-D 格式365个目录并在每个目录下创建10个文件
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: for_dir.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
PDIR=/data/test
for i in {1..365};do
DIR=`date -d "-$i day" +%F`
mkdir -pv $PDIR/$DIR
cd $PDIR/$DIR
for j in {1..10};do
touch $RANDOM.log
done
done
2、将上面的目录移动到YYYY-MM/DD/下
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: for_mv.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
#脚本安全
set -eu
DIR=/data/test
cd $DIR || { echo 无法进入 $DIR;exit 1; }
for subdir in * ;do
YYYY_MM=`echo $subdir |cut -d"-" -f1,2`
DD=`echo $subdir |cut -d"-" -f3`
[ -d $YYYY_MM/$DD ] || mkdir -p $YYYY_MM/$DD &> /dev/null
mv $subdir/* $YYYY_MM/$DD
done
rm -rf $DIR/*-*-*
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: for_scan_host.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
NET=10.0.0
for ID in {1..254};do
{
ping -c1 -W1 $NET.$ID &> /dev/null && echo $NET.$ID is up |tee -a host_list.log || echo $NET.$ID is down
}&
done
wait
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: for_sum2.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
for ((sum=0;i<=100;i++));do
let sum+=i
done
echo sum=$sum
for ((sum=0,i=1;i<=100;sum+=i,i++));do
true
done
echo sum=$sum
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: for_triangle.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
read -p "请输入三角形的行数: " line
for ((i=1;i<=line;i++));do
for ((k=0;k<=line-i;k++));do
echo -e ' \c'
done
for ((j=1;j<=2*i-1;j++));do
echo -e '&\c'
done
echo
done
[root@WMW-CentOS8 scripts]# for ((i=0;i<=100;i++));do printf "\e[4D%3d%%" $i;sleep 0.05s;done
100%[root@WMW-CentOS8 scripts]#
[root@WMW-CentOS8 scripts]# for ((;;));do echo for;sleep 1;done
for
for
for
for
for
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: for_filetype.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
for file in `ls -a /var`;do
if [ -f $file ];then
echo "$file is normal file"
elif [ -h $file ];then
echo "$file is link file"
elif [ -d "$file" ];then
echo "$file is directory file"
elif [ -p "$file" ];then
echo "$file is pipe file"
elif [ -S "$file" ];then
echo "$file is socket file"
elif [ -c "$file" ];then
echo "$file is character file"
elif [ -b "$file" ];then
echo "$file is block file"
fi
done
版本二:
#!/bin/bash
for FILE in $(ls /var);do
TYPE=$(ls -ld /var/$FILE|egrep -o '^.')
case $TYPE in
-)
echo -e "\e[1;31m$FILE is normal file.\e[0m"
;;
d)
echo -e "\e[1;32m$FILE is directory file.\e[0m"
;;
b)
echo -e "\e[1;33m$FILE is block file.\e[0m"
;;
c)
echo -e "\e[1;34m$FILE is character file.\e[0m"
;;
l)
echo -e "\e[1;35m$FILE is link file.\e[0m"
;;
p)
echo -e "\e[1;36m$FILE is pipe file.\e[0m"
;;
S)
echo -e "\e[1;37m$FILE is socket file.\e[0m"
;;
*)
echo -e "\e[1;31m$FILE is other file.\e[0m"
esac
done
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: user_for.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
for i in {1..10};do
useradd user$i
PASS=`cat /dev/urandom|tr -dc '[:alpha:]' |head -c8`
echo $PASS |passwd --stdin user$i &> /dev/null
echo user$i:$PASS >> /data/user.log
echo "user$i is created"
done
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: rc_ks.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
FILE=`ls /etc/rc.d/rc3.d/`
for i in FILE;do
find /etc/rc.d/rc3.d/S* -exec mv {} "{} start" \; &> /dev/null
find /etc/rc.d/rc3.d/K* -exec mv {} "{} stop " \; &> /dev/null
done
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: sum_triangle.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
read -p " Please input a positive interger: " INT
for ((i=1,sum=0;i<=$INT;i++));do
let sum+=i
done
echo -e "\E[1;$[RANDOM%7+31]mThe sum is $sum.\E[0m"
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: zhengchu3_sum.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
for ((i=1,sum=0;i<=100;i++));do
YU=$[i%3]
[ $YU -eq 0 ] && let sum+=i
done
echo -e "\E[1;$[RANDOM%7+31]mThe sum is $sum\E[0m"
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: for_hostcheck.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
IP=10.0.0
RED='\E[1;31m'
GREEN='\E[1;32m'
END='\E[0m'
for i in {1..254};do
{
ping -c1 -W1 ${IP}.${i} &> /dev/null && echo -e "${GREEN}${IP}.${i} is up${END}"|tee -a hostlist2.log || echo -e "${RED}${IP}.${i} is down${END}"
}&
done
wait
for ((i=1;i<=254;i++));do
ping -c1 -W1 ${IP}.${i} &> /dev/null && echo -e "${GREEN}${IP}.${i} is up.${END}" || echo -e "${RED}${IP}.${i} is down.${END}"
done
1AbCdeFgH.html
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: mkdir_html.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
#!/bin/bash
NAME=`cat /dev/urandom|tr -dc '[:alpha:]'|head -c8`
DIR=/data/testdir
for i in `seq 10`;do
if [ -d $DIR ];then
touch ${DIR}/${i}${NAME}.html
else
mkdir -p $DIR
touch ${DIR}/${i}${NAME}.html
fi
done
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: monkey.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
sum=1
for ((n=1;n<10;n++));do
sum=$[2*$[$sum+1]]
done
echo "猴子所摘桃子数: $sum"
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: check_link.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
WARNING=10
touch deny_hosts.txt
while true;do
ss -nt |sed -nr '1!s#.* ([0-9.]+):[0-9]+ *#\1#p'|sort |uniq -c |sort |
while read count ip ;do
if [ $count -gt $WARNING ];then
echo $ip is deny
grep -q "$ip" deny_hosts.txt || { echo $ip >> deny_hosts.txt;
iptables -A INPUT -s $ip -j REJECT; }
fi
done
sleep 10
done
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: while_sum.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
i=1
sum=0
while ((i<=100));do
let sum+=i
let i+=2
done
echo -e "\e[1;31mThe sum is $sum\e[0m"
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: while_hostcheck.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
IP=10.0.0
i=1
UP=0
DOWN=0
while [ $i -le 10 ];do
if ping -c1 -W1 ${IP}.$i &> /dev/null;then
echo -e "\E[1;32m${IP}.${i} is UP\E[0m"
let UP++
else
echo -e "\E[1;31m${IP}.${i} is down\E[0m"
let DOWN++
fi
let i++
done
echo -e "\E[1;32mUP is $UP\E[0m"
echo -e "\E[1;31mDOWN is $DOWN\E[0m"
wait
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-22
#FileName: while_9x9.sh
#URL: www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
i=1
while [ $i -le 9 ];do
j=1
while [ $j -le $i ];do
echo -e "\E[1;$[RANDOM%7+31]m${j}x${i}=$[i*j]\t\c\E[0m"
let j++
done
let i++
echo
done
#!/bin/bash
#
#********************************************************************
#Author: wangmingwang
#QQ: 2380821650
#Date: 2021-04-20
#FileName: while_max_min.sh
#URL: http://www.wangmingwang.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
i=1
MAX=$RANDOM
MIN=$MAX
echo $MAX
while [ $i -lt 10 ];do
N=$RANDOM
echo $N
if [ $N -gt $MAX ];then
MAX=$N
elif [ $N -lt $MIN ];then
MIN=$N
fi
let i++
done
echo MAX=$MAX,MIN=$MIN
#!/bin/bash
for i in {1…8};do
temp1=$[ $i % 2 ]
for j in {1..8};do
temp2=$[ $j % 2 ]
if [ $temp1 -eq $temp2 ];then
echo -e -n "\033[47m \033[0m"
else
echo -e -n "\033[41m \033[0m"
fi
done
echo
done
1 www.magedu.com
2 blog.magedu.com
3 study.magedu.com
4 linux.magedu.com
5 python.magedu.com
…
999 study.magedu.com
awk -F"[ .]" '{print $2}' host_list.log >> host_list.log
[root@CentOS8 ~]# awk '/^UUID/{diskfile[$3]++}END{for (i in diskfile){print i,diskfile[i]}}' /etc/fstab
swap 1
ext4 1
xfs 2
[root@CentOS8 ~]# awk '{for(i=1;i
[root@CentOS8 ~]# echo "Yd$C@M05MB%9&Bdh7dq+YVixp3vpw" |awk '{gsub(/[^0-9]/,"",$0);print $0}'
05973
[root@CentOS8 ~]# for i in {1..5000};do echo -n $((($RANDOM+90000)%100000)),>>random.txt;done
[root@CentOS8 ~]# awk -F, '{max=$1;min=$1;for(i=1;imax){max=$i}else{if($i
根据web日志或者或者网络连接数,监控当某个IP并发连接数或者短时内PV达到100,即调用防火墙命令封掉对应的IP,监控频率每隔5分钟。防火墙命令为iptables -A INPUT -s IP -j REJECT
[root@centos8 ~]#cat ss.sh
#!/bin/bash
#Version: 1.1
#**********************************************************************
ss -nt|awk -F' +|:' 'NR!=1{ip[$(NF-2)]++}END{for(i in ip){if(ip[$i]>=100){system("iptables -A INPUT -s "i" -j REJECT")}}}'
[root@centos8 ~]#chmod +x ss.sh
[root@centos8 ~]#crontab -e
*/5 * * * * root ss.sh
http://mail.magedu.com/index.html
http://www.magedu.com/test.html
http://study.magedu.com/index.html
http://blog.magedu.com/index.html
http://www.magedu.com/images/logo.jpg
http://blog.magedu.com/20080102.html
http://www.magedu.com/images/magedu.jpg
[root@CentOS8 ~]# awk -F'/' '{FQDN[$3]++}END{for(i in FQDN){print FQDN[i],i}}' fqdn.txt |sort -nr
3 www.magedu.com
2 blog.magedu.com
1 study.magedu.com
1 mail.magedu.com
inode|beginnumber|endnumber|counts|
106|3363120000|3363129999|10000|
106|3368560000|3368579999|20000|
310|3337000000|3337000100|101|
310|3342950000|3342959999|10000|
310|3362120960|3362120961|2|
311|3313460102|3313469999|9898|
311|3313470000|3313499999|30000|
311|3362120962|3362120963|2|
[root@CentOS8 ~]# awk -F '|' '!/^inode/{sum[$1]+=$4;
if(!begin[$1])begin[$1]=$2;else if(begin[$1]>$2)begin[$1]=$2;
if(!end[$1])end[$1]=$3;else if(end[$1]<$3)end[$1]=$3}
END{for(i in sum)print i"|"begin[i]"|"end[i]"|"sum[i]}' awktest.txt
106|3363120000|3368579999|30000
310|3337000000|3362120961|10103
311|3313460102|3362120963|39900
#!/usr/bin/awk -f
NR!=1{
if( $1 in inode){
if(inode[$1]["beginMinNum"]>$2){
inode[$1]["beginMinNum"]=$2
}
if(inode[$1]["endMaxNum"]<$3){
inode[$1]["endMaxNum"]=$3
}
inode[$1]["counts"]+=$4
}else{
inode[$1]["beginMinNum"]=$2;
inode[$1]["endMaxNum"]=$3;
inode[$1]["counts"]=$4;
}
}
END{
\# for (i in inode){
\# for(j in inode[i]){
\# print inode[i][j];
\# }
\# }
OFS="|";
for(i in inode){
print i,inode[i]["beginMinNum"],inode[i]["endMaxNum"],inode[i]["counts"]
}
}