`
zhengdl126
  • 浏览: 2531028 次
  • 性别: 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脚本语言编写的一个简单的作业管理系统

    在IT行业中,Linux Shell脚本语言是系统管理员和开发者常用的一种工具,用于自动化日常任务和管理系统。本项目是一个使用Linux Shell脚本实现的简单作业管理系统,它提供了对学生和教师友好的交互界面,使得作业管理...

    hadoop环境部署自动化shell脚本(伪分布式、完全分布式集群搭建).docx

    【Hadoop环境部署自动化Shell脚本】是一种高效的方法,用于快速搭建Hadoop集群,无论是用于学习还是开发。本文档提供了一个详细的脚本,涵盖了从Java环境配置到Hadoop集群的完全分布式安装的所有步骤,旨在降低...

    shell脚本shell脚本shell脚本

    Shell脚本是Linux/Unix操作系统中的命令行脚本语言,用于自动化执行一系列系统操作。它是一种强大的工具,能够帮助用户批量处理任务、管理系统资源、执行周期性任务以及整合多个命令到一个可执行文件中。在深入讲解...

    自动化运维中的脚本管理和工单管理1

    在自动化运维过程中,脚本管理旨在规范化和系统化处理各种运维脚本,确保其易于维护、扩展和协同。工单管理则关注于服务流程的标准化,提高问题处理的透明度和响应速度。 首先,脚本管理的挑战在于如何将多样化的...

    自动下载并保存GFS数据的Shell脚本

    标题中的“自动下载并保存GFS数据的Shell脚本”是指使用Linux的Shell脚本语言编写的一个程序,这个程序能够自动化地从网络上获取全球预报系统(Global Forecast System,简称GFS)的气象数据,并将其存储到本地或者...

    自动化运维脚本,Shell版本和Python版本。

    编写Shell脚本是系统管理员常用的技术,用于自动化重复性的任务。在自动化运维场景下,Shell脚本可以实现以下功能: 1. **系统配置**:设置环境变量、安装软件包、更新系统等。 2. **服务管理**:启动、停止、重启...

    非常简单的Shell菜单脚本

    在Linux系统中,Shell脚本是一种强大的自动化工具,可以实现一系列命令的集合,方便用户进行交互式操作。本文介绍的“非常简单的Shell菜单脚本”就是一种基础的Shell脚本应用,它创建了一个简单的菜单系统,使用户...

    Shell脚本专家指南Shell编程基础.pdf

    通过以上介绍,我们可以看出Shell脚本不仅适合于新手入门,也适用于开发复杂的自动化脚本。对于想要深入学习Shell编程的人来说,《Shell脚本专家指南》是一本非常有价值的参考资料。这本书详细介绍了Shell编程的基础...

    自动化部署EMQX Shell脚本

    10. **自动化脚本**:编写Shell脚本将以上步骤整合,确保部署流程的一致性。脚本应包含错误处理、日志记录和版本控制等功能,使其更适合自动化部署。 11. **持续集成**:将脚本整合到CI/CD工具(如Jenkins、GitLab ...

    Shell程序之学生管理系统

    总的来说,“Shell程序之学生管理系统”是一个利用Linux Shell脚本实现的轻量级管理工具,它通过与文本文件交互,实现了对学生、年级和学院信息的管理,展示了Shell脚本在系统自动化和数据管理方面的应用潜力。...

    Shell脚本学习教程PDF版

    Shell脚本,作为Linux/Unix系统中的编程工具,是一种强大的自动化任务执行手段。它基于Bourne shell或者其扩展版本,如bash(Bourne-Again SHell),提供了一种编写简单或复杂程序的方式,使得用户能够通过命令行...

    shell脚本实现应用层的智能路由器系统(管理界面基于php).zip

    "shell脚本实现应用层的智能路由器系统(管理界面基于php).zip" 提供了一个综合性的IT解决方案,它结合了多种技术,包括PHP编程、MySQL数据库管理和Shell脚本,用于构建一个应用层的智能路由器管理系统。...

    8145v改华为界面补shell

    这可能包括修复已知的漏洞,优化脚本效率,或者添加自定义的自动化任务。 这个过程需要一定的Linux基础和网络设备配置经验,因为涉及到的步骤包括: 1. **备份原厂设置**:在进行任何修改之前,都需要备份原有的...

    CD唱片管理系统(Shell脚本编写)

    在IT领域,Shell脚本是一种强大的工具,它允许用户通过命令行界面执行一系列自动化任务。本项目“CD唱片管理系统”是利用Shell脚本来实现对CD唱片信息的管理和操作,这既体现了Shell脚本的灵活性,也展示了其在数据...

    ANSYS workbench脚本开发指南

    这些功能使用户能够快速轻松地重放已经通过记录日志运行的分析,以及扩展功能,自动化重复分析,并通过脚本以批处理模式运行分析。 日志和脚本功能 日志记录是会话期间修改数据的所有操作的记录。用户可以根据自己...

    给自己发短信的Shell脚本利用飞信

    总的来说,这个压缩包提供了一种通过Shell脚本自动化发送短信的方法,对于需要定时提醒或者远程通知的场景非常有用。通过学习和理解这个脚本,不仅可以了解Shell编程的基本语法,还能掌握如何利用第三方服务(如飞信...

    常用shell脚本示例

    在IT领域,Shell脚本是Linux或Unix操作系统中不可或缺的一部分,它是一种强大的自动化工具,能够帮助用户执行一系列命令,简化日常任务。这个名为"常用shell脚本示例"的资源显然是为初学者设计的,目的是教授如何...

    shell脚本-大数据

    shell脚本是Linux或Unix操作系统中的一种命令解释器,用于执行一系列的命令、任务自动化和数据处理,特别适合在大数据场景下进行数据预处理、分析和调度。 首先,让我们深入理解shell脚本如何应用于大数据处理。在...

    Linux shell 脚本攻略

    Linux Shell脚本是Linux操作系统中一种强大的自动化工具,它允许用户通过编写脚本来执行一系列命令,实现系统管理和任务自动化。本书《Linux Shell脚本攻略》(第2版)深入浅出地介绍了Shell脚本的编写技巧和实战...

Global site tag (gtag.js) - Google Analytics