`
zhengdl126
  • 浏览: 2513838 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类

开发自动化系统管理脚本(界面式shell)

 
阅读更多

此工具具有如下功能:

(一)用户管理
1、修改root密码
2、删除用户帐号
3、添加用户帐号
(二)服务管理
1、开启服务
2、关闭服务
(三)防火墙/ssh认证管理
1、关闭默认防火墙,开启自定防火墙脚本(自定义脚本分为:公司环境下,以及互联网环境下)
2、修改ssh认证配置文件(采用publickey认证登录)
(四)自动设置
1、自动添加"互联网环境下"的防火墙
2、采用publickey认证登录
(五)重启功能

所有这些功能都是以函数块做的,大家可以根据自己的需求做出相应的调整以适应自己公司的需求.

开发os:centos5.2
脚本:shell
功能已经基本测试OK,不过。还需要其他朋友挖Bug...

贴些图让大家更直观点:

 

 

 

 

 

 

 
 

 AutoSetSystem.sh

    #!/bin/bash 
    ######################################################################### 
    # 
    # File:         autosetsystem.sh 
    # Description:   
    # Language:     GNU Bourne-Again SHell 
    # Version:  1.1 
    # Date:     2010-9-6 
    # WWW:      http://5ydycm.blog.51cto.com/
    ############################################################################### 
     
    zzj_key='zzjkey' 
     
    general_iptable_content="/sbin/iptables -F\n/sbin/depmod -a\n/sbin/modprobe ip_tables\n/sbin/modprobe ip_conntrack\n/sbin/iptables -A INPUT  -m state --state ESTABLISHED,RELATED -j ACCEPT\n/sbin/iptables -A INPUT -i lo -j ACCEPT\n/sbin/iptables -P INPUT DROP" 
    public_ip="ip1 ip2 ip3" 
    private_ip="ip1 ip2 ip3 ip4" 
     
    MainMenu() 
    { 
    clear 
    echo 
    echo "-------------------------------------------------------------------------" 
    tput cup 2 
    time=`date +"%Y-%m-%d"` 
    echo -ne "USER:$USER\tHOST:$HOSTNAME\tdate:$time" 
    echo 
    tput cup 3 
    echo  "-------------------------------------------------------------------------" 
    tput cup 4 20 
    echo -e "1:Manage User;" 
    tput cup 5 20 
    echo -e "2:Manage Services;" 
    tput cup 6 20 
    echo -e "3:Manage Firewall/SSH;" 
    tput cup 7 20 
    tput bold 
    echo -e "4:AutoSet;" 
    tput sgr0 
    tput cup 8 20 
    echo -e "5:Reboot;" 
    tput cup 9 20 
    echo -e "6:Quit;" 
    tput cup 10  
    echo  "--------------------------------------------------------------------------" 
    echo -n "You choice [1,2,3,4,5,6]:" 
    read AA 
    case $AA in 
    1) 
    ManageUser 
    ;; 
    2) 
    ManageServices 
    ;; 
    3) 
    ManageFirewall 
    ;; 
    4) 
    AutoSet 
    ;; 
    5) 
    echo -n "Are you sure reboot system[y|n]?" 
    read answer 
    if [ $answer == "y" ];then 
    shutdown -r now 
    exit 0 
    else 
    echo -n "You forego reboot system!" 
    sleep 2 
    fi 
    ;; 
    *) 
    Quit 
    ;; 
    esac 
    } 
    AutoSet(){ 
    EnableOutFirewall 
    echo -e "\n" 
    PublickeyAuthenticate 
    } 
     
    AddUser(){ 
    echo -n "Please input add user name:" 
    read username 
    (awk -F':' '{print $1}' /etc/passwd|grep ^$username$) && (echo "Add user faild because user exists!"&&sleep 2)||(useradd $username&&passwd $username&&sleep 2)} 
     
    DeleteUser(){ 
    echo -n "Please input delete user name:" 
    read username 
    echo -n "Are you sure delete $username[y|n]?" 
    read answer 
    if [ $answer == "y" ];then 
    (awk -F':' '{print $1}' /etc/passwd|grep ^$username$)&&(userdel $username&&echo "user delete sucessfull!"&&sleep 2)||(echo "Delete user faild because user account not exists!"&&sleep 2) 
    else 
    echo -n "You forego delete $username account!" 
    sleep 2 
    fi 
    } 
     
    ModifyRootpwd(){ 
    echo -n "Are you sure modify root password[y|n]?" 
    read answer 
    if [ $answer == "y" ];then 
    passwd root 
    sleep 2 
    else 
    echo -n "You forego modify root password!" 
    sleep 2 
    fi 
    } 
     
    ViewUser(){ 
    more /etc/passwd 
    tput bold  
    echo "Wait 8 sec!" 
    sleep 8  
    tput sgr0  
    } 
     
    ManageUserMenu(){ 
    clear 
    echo 
    echo "-------------------------------------------------------------------------" 
    tput cup 2 
    time=`date +"%Y-%m-%d"` 
    echo -ne "USER:$USER\tHOST:$HOSTNAME\tdate:$time" 
    echo 
    tput cup 3 
    echo  "-------------------------------------------------------------------------" 
    tput cup 4 20 
    echo -e "1:Add User;" 
    tput cup 5 20 
    echo -e "2:Delete User;" 
    tput cup 6 20 
    echo -e "3:Modify root password;" 
    tput cup 7 20 
    echo -e "4:View User;" 
    tput cup 8 20 
    echo -e "5:Quit;" 
    tput cup 9  
    echo  "--------------------------------------------------------------------------" 
    echo -n "You choice [1,2,3,4,5]:" 
    read BB  
    case $BB in 
    1) 
    AddUser 
    ;; 
    2) 
    DeleteUser 
    ;; 
    3) 
    ModifyRootpwd 
    ;; 
    4) 
    ViewUser 
    ;; 
    *) 
    echo "Quit" 
    break 
    ;; 
    esac 
    } 
     
    EnableServices(){ 
    echo -n "Please input enable service name:" 
    read servicename 
    echo -n "Are you sure enable $servicename[y|n]?" 
    read answer 
    if [ $answer == "y" ];then 
    (chkconfig --list|awk '{print $1}'|grep ^$servicename$)&&(chkconfig --level 345 $servicename on&&echo "service enable sucessfull!"&&sleep 2)||(echo "service enable faild because service not exists!"&&sleep 2) 
    else 
    echo -n "You forego enable $servicename!" 
    sleep 2 
    fi 
    } 
     
    DisableServices(){ 
    echo -n "Please input disable service name:" 
    read servicename 
    echo -n "Are you sure disable $servicename[y|n]?" 
    read answer 
    if [ $answer == "y" ];then 
    (chkconfig --list|awk '{print $1}'|grep ^$servicename$)&&(chkconfig --level 345 $servicename off&&echo "service diable sucessfull!"&&sleep 2)||(echo "service disable faild because service not exists!"&&sleep 2) 
    else 
    echo -n "You forego disable $servicename!" 
    sleep 2 
    fi 
    } 
     
    ViewServices(){ 
    chkconfig --list 
    tput bold 
    echo "Wait 8 sec!" 
    sleep 8 
    tput sgr0 
    } 
     
    ManageServicesMenu(){ 
    clear 
    echo 
    echo "-------------------------------------------------------------------------" 
    tput cup 2 
    time=`date +"%Y-%m-%d"` 
    echo -ne "USER:$USER\tHOST:$HOSTNAME\tdate:$time" 
    echo 
    tput cup 3 
    echo  "-------------------------------------------------------------------------" 
    tput cup 4 20 
    echo -e "1:Enable Services;" 
    tput cup 5 20 
    echo -e "2:Disable Services;" 
    tput cup 6 20 
    echo -e "3:View Services;" 
    tput cup 7 20 
    echo -e "4:Quit;" 
    tput cup 8  
    echo  "--------------------------------------------------------------------------" 
    echo -n "You choice [1,2,3,4]:" 
    read CC  
    case $CC in 
    1) 
    EnableServices 
    ;; 
    2) 
    DisableServices 
    ;; 
    3) 
    ViewServices 
    ;; 
    *) 
    echo "Quit" 
    break 
    ;; 
    esac 
    } 
     
    EnableCompanyFirewall(){ 
    echo -n "Are you sure enable firewall[y|n]?" 
    read answer 
    if [ $answer == "y" ];then 
    if [ ! -d /scripts ];then 
    mkdir /scripts 
    fi 
    echo -e $general_iptable_content >/scripts/start_firewall.sh 
    for ip in $private_ip 
    do 
    echo "/sbin/iptables -A INPUT -s $ip -p tcp --dport 22 -j ACCEPT" >>/scripts/start_firewall.sh 
    done 
    echo "sh /scripts/start_firewall.sh" >>/etc/rc.local 
    chmod +x /scripts/start_firewall.sh 
    sh /scripts/start_firewall.sh 
    echo "Enable Firewall sucessful!" 
    sleep 3 
    else 
    echo -n "You forego enable firewall!" 
    sleep 2 
    fi 
    } 
    EnableOutFirewall(){ 
    echo -n "Are you sure enable firewall[y|n]?" 
    read answer 
    if [ $answer == "y" ];then 
    if [ ! -d /scripts ];then 
    mkdir /scripts 
    fi 
    echo -e $general_iptable_content >/scripts/start_firewall.sh 
    for ip in $public_ip 
    do 
    echo "/sbin/iptables -A INPUT -s $ip -p tcp --dport 22 -j ACCEPT" >>/scripts/start_firewall.sh 
    done 
    echo "sh /scripts/start_firewall.sh" >>/etc/rc.local 
    chmod +x /scripts/start_firewall.sh 
    sh /scripts/start_firewall.sh 
    echo "Enable Firewall sucessful!" 
    sleep 3 
    else 
    echo -n "You forego enable firewall!" 
    sleep 2 
    fi 
    } 
     
    FirewallEnvMenu(){ 
    clear 
    echo 
    echo "-------------------------------------------------------------------------" 
    tput cup 2 
    time=`date +"%Y-%m-%d"` 
    echo -ne "USER:$USER\tHOST:$HOSTNAME\tdate:$time" 
    echo 
    tput cup 3 
    echo  "-------------------------------------------------------------------------" 
    tput cup 4 20 
    echo -e "1:Enable Company Env Firewall;" 
    tput cup 5 20 
    echo -e "2:Enable Out Env Firewall;" 
    tput cup 6 20 
    echo -e "3:Quit;" 
    tput cup 7  
    echo  "--------------------------------------------------------------------------" 
    echo -n "You choice [1,2,3]:" 
    read EE  
    case $EE in 
    1) 
    EnableCompanyFirewall 
    ;; 
    2) 
    EnableOutFirewall 
    ;; 
    *) 
    echo "Quit" 
    break 
    ;; 
    esac 
    } 
    CustomizeFirewall() 
    { 
    while true 
    do 
    FirewallEnvMenu 
    done 
    } 
    PublickeyAuthenticate() 
    { 
    echo -n "Are you sure enable publickey auth[y|n]?" 
    read answer 
    if [ $answer == "y" ];then 
    if [ ! -d /root/.ssh ];then 
    mkdir /root/.ssh 
    fi 
    touch /root/.ssh/authorized_keys 
    echo $zzj_key >/root/.ssh/authorized_keys 
    cp /etc/ssh/sshd_config /tmp/sshd_config_bak 
    sed 's/^PasswordAuthentication yes$/PasswordAuthentication no/' /etc/ssh/sshd_config > /etc/ssh/tmp_sshd_config 
    sed 's/^#PubkeyAuthentication yes$/PubkeyAuthentication yes/' /etc/ssh/tmp_sshd_config > /etc/ssh/tmp1_sshd_config 
    sed 's/^#AuthorizedKeysFile/AuthorizedKeysFile/' /etc/ssh/tmp1_sshd_config > /etc/ssh/tmp_sshd_config 
    rm -fr /etc/ssh/sshd_config 
    rm -fr /etc/ssh/tmp1_sshd_config 
    mv /etc/ssh/tmp_sshd_config /etc/ssh/sshd_config 
    kill -HUP `cat /var/run/sshd.pid` 
    echo "Please use public key try login agains!" 
    sleep 5  
    else 
    echo -n "You forego publickey auth!" 
    sleep 2 
    fi 
    } 
     
    ManagerFirewallMenu(){ 
    clear 
    echo 
    echo "-------------------------------------------------------------------------" 
    tput cup 2 
    time=`date +"%Y-%m-%d"` 
    echo -ne "USER:$USER\tHOST:$HOSTNAME\tdate:$time" 
    echo 
    tput cup 3 
    echo  "-------------------------------------------------------------------------" 
    tput cup 4 20 
    echo -e "1:Enable Customize Firewall;" 
    tput cup 5 20 
    echo -e "2:Enable Publickey Authenticate;" 
    tput cup 6 20 
    echo -e "3:Quit;" 
    tput cup 7  
    echo  "--------------------------------------------------------------------------" 
    echo -n "You choice [1,2,3]:" 
    read DD  
    case $DD in 
    1) 
    CustomizeFirewall 
    ;; 
    2) 
    PublickeyAuthenticate 
    ;; 
    *) 
    echo "Quit" 
    break 
    ;; 
    esac 
    } 
     
    ManageUser () 
    { 
    while true 
    do 
    ManageUserMenu 
    done 
    } 
     
     
    ManageServices(){ 
    while true 
    do 
    ManageServicesMenu 
    done 
    } 
    ManageFirewall() 
    { 
    while true 
    do 
    ManagerFirewallMenu 
    done 
    } 
     
    Quit() 
    { 
    echo "Quit" 
    break 
    } 
     
    while true  
    do 
    MainMenu 
    done 
 

 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    Linux下Shell从入门到精通完整版视频.zip

    13.Linux下自动化运维企业案例.mp4 14.Linux系统增量备份脚本.mp4 15.自动收集服务器硬件系统信息脚本.mp4 16.Shell编程之磁盘监控报警脚本_0.mp4 17.Shell批量监控服务发送邮件报警.mp4 18.Shell编程之实战WEB界面...

    Linux下Shell编程从入门到精通视频教程.txt

    14、Linux下自动化运维企业案例.mp4 13、Linux系统增量备份脚本.mp4 12、Shell编程四剑客及案例详解.mp4 11、Shell编程之SED及GREP综合讲解.mp4 10、Linux下深入编程之函数及数组编程.mp4 09、Shell编程之函数及案例...

    bash-2.05a-2.05b.diff.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-2.04-2.05.diff.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-1.14.0-1.14.1.diff.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-2.01-2.01.1.diff.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-2.02.1-2.03.diff.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bashref.texi.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-2.02-2.02.1.diff.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-2.01.1-2.02.diff.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-1.14.3-1.14.4.diff.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-2.0-2.01.diff.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-1.14.6-1.14.7.diff.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-1.14.5-1.14.6.diff.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-2.05b-3.0.diff.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-2.05-2.05a.diff.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-4.4-rc1.tar.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-5.2-beta.tar.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-5.2-alpha.tar.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

    bash-5.2.15.tar.gz

    Bash 是一种广泛使用的...Bash 作为一个强大的命令行工具,不仅用于日常的文件管理和系统操作任务,而且在自动化脚本、任务调度和高级编程方面也非常有用。它的灵活性和易用性使其成为开发者和系统管理员的首选 shell。

Global site tag (gtag.js) - Google Analytics