#!/bin/bash RED="echo -e \E[1;31m" GREEN="echo -e \E[1;32m" END="\E[0m" os_release(){ if grep -i -q ubuntu /etc/os-release;then echo ubuntu elif grep -i -q centos /etc/os-release;then echo centos else echo "os can not be supported!" fi } install_mysql(){ if [ `os_type` = centos ] ;then yum install mysql -y elif [ `os_type` = ubuntu ] ;then apt install mysql -y else echo "os can not be supported" fi ${GREEN}安装成功$END } install_httpd(){ if [ `os_type` = centos ] ;then yum install httpd -y elif [ `os_type` = ubuntu ] ;then apt install apache2 -y else echo "os can not be supported" fi ${GREEN}安装成功$END } ssh_expect(){ NET=10.0.0 user=root password=qq123456 IPLIST=" 137 101 238 " for ID in $IPLIST ;do ip=$NET.$ID expect <<eof spawn ssh $user@$ip expect { "yes/no" { send "yes\n";exp_continue } "password" {send "$password\n" } "#" { send "exit\n" } } eof done } PS3="请选择功能(1-4): " select menu in 安装mysql 安装apache 免密钥登录主机 退出;do case $REPLY in 1) install_mysql ;; 2) install_httpd ;; 3) ssh_expect ;; 4) break ;; *) echo "输出错误" esac done
标签:centos,主机,echo,expect,install,type,os,登陆 From: https://www.cnblogs.com/Zhou2001/p/16986325.html