centos7 lvm合并分区脚本初探-linux性能测试

时间:2021-08-06 23:52:44
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