zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    进程池的回调函数
    进程通信(multiprocessing.Queue)
    自动化批量管理工具salt-ssh
    自动化批量管理工具pssh
    Saltstack自动化操作记录(2)-配置使用
    Saltstack自动化操作记录(1)-环境部署
    RocketMQ 简单梳理 及 集群部署笔记
    CentOS7下单机部署RabbltMQ环境的操作记录
    centos6下ActiveMQ+Zookeeper消息中间件集群部署记录
    [Centos6.9下RabbitMQ集群部署记录]
  • 原文地址:https://www.cnblogs.com/xiaofeng666/p/12239819.html
Copyright © 2011-2022 走看看