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分區合併html

 

#!/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 -ajava

 

參考https://www.cnblogs.com/flintlovesam/p/6677037.htmllinux

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

${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


記憶的方法爲:c++

複製代碼 代碼以下:

# 是 去掉左邊(鍵盤上#在 $ 的左邊)
%是去掉右邊(鍵盤上% 在$ 的右邊)
單一符號是最小匹配;兩個符號是最大匹配
 
其餘腳本方式參考
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 擴容分區docker

   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和網關 網卡名字 記得修改ubuntu

#!/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安裝腳本centos

#!/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

 而後手動執行bash

source /etc/profile.d/jdk8.sh

 

關鍵字查詢文件app

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 #表示密碼當即過時須要修改密碼
相關文章
相關標籤/搜索