centos7 lvm合并分区脚本初探-linux性能测试 -centos7修改网卡名字-jdk环境安装脚本-关键字查询文件-批量添加用户

1.
#!/bin/bash lvmdiskscan | grep centos > /root/a.txt a=`sed -n '1p' /root/a.txt` b=`sed -n '2p' /root/a.txt` c=`sed -n '3p' /root/a.txt` cat <<eof ** 1. 分区 $a** ** 2. 分区 $b** ** 3. 分区 $c** eof

 

2完成版centos分区合并

 

#!/bin/bash
lvmdiskscan | grep centos > /root/a.txt
cat /root/a.txt | while read ips;
do
a1=`echo $ips|awk '{ print $1 }'`
a2=`echo $ips|awk '{ print $3 }'`
a3=`echo ${a2%.*}`
echo $a1
echo $a3
done
read -p "remove lv: " remove2
read -p "add lv: " add2
read -p "big : " big
rmfstab=`echo ${remove2##*/}`
addlvname=`echo ${add2##*/}`
addlvtype=`blkid | grep $addlvname | awk -F "[\"\"]" '{print $4}'`
umount $remove2
lvremove $remove2
lvextend -L +"$big"G $add2
# 变量记得加双引号
if [[ $addlvtype == xfs ]] ;then
# 根据字符串判断
xfs_growfs $add2
else
resize2fs $add2
fi
sed -i "/"$rmfstab"/d" /etc/fstab
# 删除移除lv开机挂载 注意使用时删除注释内容
mount -a

 

参考https://www.cnblogs.com/flintlovesam/p/6677037.html

https://www.cnblogs.com/keanuyaoo/p/3359838.html

${file#*/}:删掉第一个 / 及其左边的字符串:dir1/dir2/dir3/my.file.txt
${file##*/}:删掉最后一个 /  及其左边的字符串:my.file.txt
${file#*.}:删掉第一个 .  及其左边的字符串:file.txt
${file##*.}:删掉最后一个 .  及其左边的字符串:txt
${file%/*}:删掉最后一个  /  及其右边的字符串:/dir1/dir2/dir3
${file%%/*}:删掉第一个 /  及其右边的字符串:(空值)
${file%.*}:删掉最后一个  .  及其右边的字符串:/dir1/dir2/dir3/my.file
${file%%.*}:删掉第一个  .   及其右边的字符串:/dir1/dir2/dir3/my


记忆的方法为:

复制代码 代码如下:

# 是 去掉左边(键盘上#在 $ 的左边)
%是去掉右边(键盘上% 在$ 的右边)
单一符号是最小匹配;两个符号是最大匹配
 
其他脚本方式参考
https://www.cnblogs.com/out8/p/4353017.html
 
centos7 性能测试
#! /bin/bash
#==============================================================#
#   Description:  Unixbench script                             #
#   Author: Teddysun <i@teddysun.com>                          #
#   Intro:  https://teddysun.com/245.html                      #
#==============================================================#
cur_dir=/opt/unixbench

# Check System
[[ $EUID -ne 0 ]] && echo 'Error: This script must be run as root!' && exit 1
[[ -f /etc/redhat-release ]] && os='centos'
[[ ! -z "`egrep -i debian /etc/issue`" ]] && os='debian'
[[ ! -z "`egrep -i ubuntu /etc/issue`" ]] && os='ubuntu'
[[ "$os" == '' ]] && echo 'Error: Your system is not supported to run it!' && exit 1

# Install necessary libaries
if [ "$os" == 'centos' ]; then
    yum -y install make automake gcc autoconf gcc-c++ time perl-Time-HiRes
else
    apt-get -y update
    apt-get -y install make automake gcc autoconf time perl
fi

# Create new soft download dir
mkdir -p ${cur_dir}
cd ${cur_dir}

# Download UnixBench5.1.3
if [ -s UnixBench5.1.3.tgz ]; then
    echo "UnixBench5.1.3.tgz [found]"
else
    echo "UnixBench5.1.3.tgz not found!!!download now..."
    if ! wget -c https://dl.lamp.sh/files/UnixBench5.1.3.tgz; then
        echo "Failed to download UnixBench5.1.3.tgz, please download it to ${cur_dir} directory manually and try again."
        exit 1
    fi
fi
tar -zxvf UnixBench5.1.3.tgz && rm -f UnixBench5.1.3.tgz
cd UnixBench/

#Run unixbench
make
./Run

echo
echo
echo "======= Script description and score comparison completed! ======= "
echo
echo

 

lvm 扩容分区

   41  /sbin/fdisk /dev/sda
   49  partprobe #同步分区表到硬盘
   50  ls /dev/sda*
   51  pvcreate /dev/sda3
   52  vgs
   53  vgextend centos /dev/sda3
   54  vgs
   55  lvs
   56  df -h
   57  vgs
   58  lvextend -L +200G /dev/mapper/centos-root
xfs_growfs /dev/mapper/centos-root #扩容真实大小

 修改网卡名字脚本 ip和网关 网卡名字 记得修改

#!/bin/bash
NETIP=192.168.120.72
NETGATWAY=192.168.120.1
# 用不到HOSTNAME=dockercang.cn
DNS1=223.5.5.5
ethold=ens192

cat << EOF
+------------------------------------------------------------------+
|     **********  Welcome to CentOS 7.x Rename Network  **********    |
+------------------------------------------------------------------+
EOF
[ `whoami` != "root" ] && echo "please use root" && exit 1
function format() {
    echo -e "\033[32m Success!!!\033[0m\n"
    echo "#########################################################"
}

echo "修改配置文件"
rm -rf /etc/sysconfig/network-scripts/ifcfg-$ethold
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=$NETIP
PREFIX=24
GATEWAY=$NETGATWAY
DNS1=$DNS1
EOF
format

echo "编辑内核信息"
cat > /etc/sysconfig/grub << EOF
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb net.ifnames=0 biosdevname=0 quiet"
GRUB_DISABLE_RECOVERY="true"
EOF
format
echo "生成启动菜单"
grub2-mkconfig -o /boot/grub2/grub.cfg
format
reboot

 jdk安装脚本

#!/bin/bash
wget http://192.168.130.150/jdk/jdk-8u211-linux-x64.tar.gz
tar xf jdk-8u211-linux-x64.tar.gz -C /usr/local/
echo "export JAVA_HOME=/usr/local/jdk1.8.0_211" >> /etc/profile.d/jdk8.sh
echo "export CLASS_PATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/jar/tools.jar:\$JAVA_HOME/jre/lib" >> /etc/profile.d/jdk8.sh
echo "export PATH=\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin:\$PATH" >> /etc/profile.d/jdk8.sh
echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/apr/lib" >> /etc/profile.d/jdk8.sh

chmod +x /etc/profile.d/jdk8.sh
source /etc/profile.d/jdk8.sh
java -version

 然后手动执行

source /etc/profile.d/jdk8.sh

 

关键字查询文件

grep -rn "aaa" /root/
grep -r "aaa" /root/
grep -Rn "data_chushou_pay_info" *.py #根据关键字过滤

 批量添加用户

vi adduser.sh

#!/bin/bash
for name in $(more users.list)
do
if [ -n "$name" ];then
useradd -m $name
echo
echo $name"123456" | passwd --stdin "$name"
echo
echo "user $name's password change"
else
echo
echo 'The username is null'
fi
done

vi users.list

Jason
Miles
James
sh adduser.sh

 

删除用户脚本

#!/bin/bash
userdel $1
cd /home/
rm -rf $1
cd /var/spool/mail && rm -f $1

 另一种加用户方式

#!/bin/sh
for i in $(cat deyimingdan)
do
useradd $i
echo $i | passwd --stdin $i
chage -d 0 $i
        echo "$i        ALL=(ALL)       ALL" >> /etc/sudoers
done
chage -d 0 #表示密码立即过期需要修改密码

 

posted @ 2019-05-14 10:19  夜辰雪扬  阅读(521)  评论(0编辑  收藏  举报