• shell案例


    1、创建用户

    useradd01.sh

     1 #!/bin/bash
     2 
     3 ###############################
     4 
     5 #useradd              #
     6 
     7 #v1.0 by  userf 2019.08.0     #
     8 
     9 ###############################
    10 
    11 read  -p  "Please input  number: "    num
    12 
    13 if [[ ! “$num” =~  ^[0-9]+$ ]];then  #[ ]不支持正则表达式,故使用扩展的[[  ]]来进行匹配
    14 
    15   echo "error number"
    16 
    17   exit
    18 
    19 fi
    20 
    21 read  -p  "Please input  prefix: "       prefix
    22 
    23 if [ -z "$prefix" ];then
    24 
    25   echo "error prefix"
    26 
    27   exit
    28 
    29 fi
    30 
    31 redcolor="e[1;31m"
    32 
    33 colorend="e[0m"
    34 
    35 for   i    in   `seq  $num`
    36 
    37 do
    38 
    39   user=$prefix$i
    40 
    41   useradd  $user
    42 
    43   echo "123" | passwd  --stdin  $user &>/dev/null
    44 
    45   if [ $? -eq 0 ];then
    46 
    47     echo  -e   ${redcolor}The $user  is created${colorend}  successfully!
    48 
    49   fi
    50 
    51 done

    多重yum源选择

     1 #!/usr/bin/bash
     2 
     3 #yum config case
     4 
     5 yum_server=10.96.124.68
     6 
     7 os_version=$(cat /etc/redhat-release |awk '{print $4}'|awk -F"." '{print $1"."$2}')
     8 
     9 [ -d  /etc/yum.repos.d ] || mkdir  /etc/yum.repos.d/bak
    10 
    11 mv  /etc/yum.repos.d/* .repo   /etc/yum.repos.d/bak
    12 
    13 case  "$os_version"  in 
    14 
    15 8)
    16 
    17   wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
    18 
    19   ;;
    20 
    21 7.3)
    22 
    23   cat >> /etc/yum.repos.d/centos7u3.repo <<eof
    24   > [centos7u3]
    25   > name=centos7u3
    26   > baseurl=ftp://$yum_server/centos7u3
    27   > gpgcheck=0
    28   > eof
    29 
    30   ;;
    31 
    32 6.8)
    33 
    34   wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
    35 
    36   ;;
    37 
    38 *)
    39 
    40   echo "error"
    41 
    42 esac
  • 相关阅读:
    万能分页方法!机会难得,在此送给大家
    Java长存!12个Java长久占居主要地位的原因
    angularjs1.x radio组checkbox组
    js动态显示vlc视频直播
    Lodop 分页详解,可详细了呢
    lodop 实现分页打印账单 最后一页右下角加入确认签字
    lodop分页,页眉页脚,foreach分页代码
    ajax最简单验证
    Httpcilent获取带验证码的网站内容
    设计模式(转载)
  • 原文地址:https://www.cnblogs.com/xiaofeng666/p/12239819.html
Copyright © 2020-2023  润新知