linux脚本编写图形,shell图形化界面脚本实现
#!/bin/bash
. /etc/rc.d/init.d/functions
#此脚本用于---服务运维
#time:2018/10/29
#@一个热爱生活的好少年_lzy
echo_red() {
stty erase '^H'
echo -n -e "\033[31m$1\033[0m"
}
echo_red_enter() {
echo -e "\033[31m$1\033[0m"
}
echo_green() {
stty erase '^H'
echo -n -e "\033[32m$1\033[0m"
}
echo_green_enter() {
echo -e "\033[32m$1\033[0m"
}
function clean_buffer(){
echo 3 > /proc/sys/vm/drop_caches
}
function warning
{
if [[ $# = 2 ]];then
[[ "$1" = 0 ]] && action "$2" /bin/true || action "$2" /bin/false
elif [[ $# = 1 ]];then
icontent=$(cat $ERROR_LOG)
if [[ -n "$icontent" ]];then
action "$1" /bin/false && cat $ERROR_LOG >> $LOG && rm -rf $ERROR_LOG && exit
else
action "$1" /bin/true
fi
fi
}
#进程
#定义全局变量
hybird_select_animo=
#界面2
function radiolist() {
DISTROS=$(whiptail --title "请选择所需要的模块" --radiolist \
"请选择所需要的脚本?" 15 60 4 \
"hybird0" "/与网络检测" ON \
"hybird1" "中架构" OFF \
"hybird2" "架构" OFF \
"hybird3" "他()" OFF 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
hybird_select_animo=$DISTROS
echo_green_enter "您所选择的模块 $hybird_select_animo"
else
echo "You chose Cancel."
fi
}
#界面3
function hybird0 {
OPTION=$(whiptail --title "请选择需要检测的模块" --menu "Choose your option" 15 60 4 \
"1" "网络联通性)" \
"2" "t服务检测" \
"3" "s服务器检测" \
"4" "all(融合)" 3>&1 1>&2 2>&3)
exitstatus=$?
#echo > $hytmp
#shell数组如何传递到函数中
if [ $exitstatus = 0 ]; then
#echo "Your chosen option:" $OPTION
if [ $OPTION == 1 ];then
echo_green_enter "网络联通性检测:"
#network_test
network_test0
elif [ $OPTION == 2 ];then
echo "开始检服务:"
# Hardware 变量融t
#Process_test $Process_all_rh
echo_green "本次共检测nginx rsync memcached 服务"
Process_all_rh=("nginx" "rsync" "memcached")
Process_test "${Process_all_rh[*]}"
Process_all_rh1=("telt" "tele" "ant")
Process_test_java "${Process_all_rh1[*]}"
#swift_service_test
elif [ $OPTION == 3 ];then
swift_service_test
elif [ $OPTION == 4 ];then
echo_green_enter "----性能测试:"
all
fi
else
echo "You chose Cancel."
fi
}
#swift进程检测
function swift_service_test(){
echo_red "swift进程检测:"
ps -ef | grep swift
sleep 5
if (whiptail --title "是否继续启动swift服务" --yesno "建议:相关存储服务服务 是否继续执行:请选择" 15 80) then
echo "You chose Yes. 开始执行环境检测!"
swift_proxy restart
else
echo "You chose No. Exit status was $?."
fi
}
function swift_proxy() {
systemctl $1 openstack-swift-proxy.service memcached.service rsyncd.service openstack-keystone.service
systemctl $1 openstack-swift-account.service openstack-swift-account-auditor.service openstack-swift-account-reaper.service openstack-swift-account-replicator.service
systemctl $1 openstack-swift-container.service openstack-swift-container-auditor.service openstack-swift-container-replicator.service openstack-swift-container-updater.service
systemctl $1 openstack-swift-object.service openstack-swift-object-auditor.service openstack-swift-object-replicator.service openstack-swift-object-updater.service
}
function swift_object() {
systemctl $1 rsyncd.service
systemctl $1 openstack-swift-account.service openstack-swift-account-auditor.service openstack-swift-account-reaper.service openstack-swift-account-replicator.service
systemctl $1 openstack-swift-container.service openstack-swift-container-auditor.service openstack-swift-container-replicator.service openstack-swift-container-updater.service
systemctl $1 openstack-swift-object.service openstack-swift-object-auditor.service openstack-swift-object-replicator.service openstack-swift-object-updater.service
}
# #查看telnet命令是否存在
function network_test0 {
#查看telnet命令是否存在
which "telnet" > /dev/null
if [ $? -eq 0 ]
then
echo_green_enter "telnet is exist"
network_telnet
else
echo_red "telnet not exist"
echo "请先安装telnet服务:yum install -y telnet 即可。"
fi
}
#网络层面检测
function network_telnet {
#如果telnet安装成功
#shell数组
array=(www.baidu.com)
eco_print1="检测结果:该服务器连接"
eco_print3="主站服务器正常ok"
eco_print4="主站服务器异常:请尽快开通。"
#遍历数组
for(( i=0;i
do
#echo ${array[i]};
NPORT1=`echo ""|telnet ${array[i]} 443 2>/dev/null|grep "\^]"|wc -l`
if [[ $NPORT1 == 1 ]];then
eco_print=${eco_print1}${array[i]}${eco_print3}
echo_green ${eco_print}
else
eco_print=${eco_print1}${array[i]}${eco_print4}
echo_red ${eco_print}
whiptail --title "警告" --msgbox ${eco_print} 10 60
fi
sleep 1
echo " "
done;
}
#服务进程检测
#变量
eco_Pro_print1="检测结果:该服务"
eco_Pro_print3="已启动正常ok"
eco_Pro_print4="异常未启动(并检测服务器是否部署该服务)"
#function Arrayassignment(){
#}
#将所传的服务进行进程检测
function Process_test() {
arr=$1
#轮询上述所传的数组;
for i in ${arr[*]}; do
echo $i
#echo ${array[i]};
A=`ps -C $i --no-header |wc -l`
echo_green "正在查看服务进程是否存在:"
ps -ef | grep $i
sleep 3
if [ $A -eq 0 ];then ## 如果没有进程值得为 零 服务未启动
#弹出是否重启服务界面
#if nginx如何下 teleport(java服务)需要/etc/ini.d/teleport start
#
#if 是rsync的话 需要变更为rsyncd
echo_red "目前无该服务进程"
if [[ $i == rsync ]]; then
#statements
value=${i}"d"
else
value=$i
fi
echo $value
restart_Process_Interface $value
else
echo_green "该服务正常:进程已启动----------------"
fi
done
}
function Process_test_java() {
arr=$1
#轮询上述所传的数组;
for i in ${arr[*]}; do
echo $i
#echo ${array[i]};
#A=`ps -C $i --no-header |wc -l`
echo_green "正在查看服务进程是否存在:"
ps -ef | grep $i
if [[ $i == teleport ]]; then
#statements
Pvalue=${i}"/"
elif [[ $i == holmes ]]; then
#statements
Pvalue=${i}"/"
else
Pvalue=$i
fi
A=`ps -ef | grep $Pvalue | wc -l`
sleep 3
if [ $A -eq 1 ];then ## 如果没有进程值得为 零 服务未启动
#弹出是否重启服务界面
#if nginx如何下 (java服务)需要/etc/ini.d/
#
#if 是rsync的话 需要变更为rsyncd
echo_red "目前无该服务进程:"
if [[ $i == rsync ]]; then
#statements
value=${i}"d"
else
value=$i
fi
echo $value
restart_Process_Interface_java $value
else
echo_green "该服务正常:进程已启动----------------"
fi
done
}
#是否重启服务
function restart_Process(){
if (whiptail --title "欢迎使用维护脚本" --yesno "提示:是否启动该服务:请选择" 15 80) then
echo "You chose Yes. 正在启动服务!"
#radiolist
if [[ $hybird_select_animo == hybird0 ]]; then
hybird0
#statements:
elif [[ $hybird_select_animo == hybird1 ]]; then
#statements
hybird1
elif [[ $hybird_select_animo == hybird2 ]]; then
#statements
hybird2
elif [[ $hybird_select_animo == hybird3 ]]; then
#statements
hybird3
fi
else
echo "You chose No. Exit status was $?."
fi
}
#变量 shell 字符串拼接/截取:
eco_Pro_Interfac_print1="是否重启该服务:"
eco_Pro_Interfac_print3="已启动正常ok"
eco_Pro_Interfac_print4=":服务器异常启动失败(并检测服务器是否部署该服务)"
#界面显示并抉择是否重启/并检测(nginx/rabbit/rsyslog/rsyncd/)
function restart_Process_Interface(){
restart_Process_name=$1
eco_Pro_Interfac_print=${eco_Pro_Interfac_print1}${restart_Process_name}
if (whiptail --title $eco_Pro_Interfac_print --yesno "提示: 是否继续执行:请选择" 15 80) then
echo "You chose Yes. 开始启动服务!"
systemctl start $restart_Process_name
if [[ $restart_Process_name == rsyncd ]]; then
#statements
restart_Process_name=rsync
fi
#如何判断进程是否存在
A=`ps -C $restart_Process_name --no-header |wc -l`
if [ $A -eq 0 ];then ## 如果没有进程值得为 零 服务未启动
#
eco_Pro_Interfac_print_error=${restart_Process_name}${eco_Pro_Interfac_print4}
echo_red $eco_Pro_Interfac_print_error
else
eco_Pro_Interfac_print_suc=${restart_Process_name}${eco_Pro_Interfac_print3}
echo_green $eco_Pro_Interfac_print_suc
fi
else
echo "You chose No. Exit status was $?."
fi
}
function restart_Process_Interface_java(){
restart_Process_name=$1
eco_Pro_Interfac_print=${eco_Pro_Interfac_print1}${restart_Process_name}
if (whiptail --title $eco_Pro_Interfac_print --yesno "提示: 是否继续执行:请选择" 15 80) then
echo "You chose Yes. 开始启动服务!"
cd /etc/init.d
./$restart_Process_name start
if [[ $restart_Process_name == rsyncd ]]; then
#statements
restart_Process_name=rsync
fi
A=`ps -ef | grep $Pvalue | wc -l`
if [ $A -eq 1 ];then ## 如果没有进程值得为 零 服务未启动
#如何进行字符串拼接
eco_Pro_Interfac_print_error=${restart_Process_name}${eco_Pro_Interfac_print4}
echo_red $eco_Pro_Interfac_print_error
else
eco_Pro_Interfac_print_suc=${restart_Process_name}${eco_Pro_Interfac_print3}
echo_green $eco_Pro_Interfac_print_suc
fi
else
echo "You chose No. Exit status was $?."
fi
}
#执行入口图形化界面
if (whiptail --title "欢迎使用---维护脚本" --yesno "提示:是否继续执行:请选择" 15 80) then
echo "You chose Yes. 开始执行环境检测!"
radiolist
if [[ $hybird_select_animo == hybird0 ]]; then
hybird0
#statements
elif [[ $hybird_select_animo == hybird1 ]]; then
#statements
hybird1
elif [[ $hybird_select_animo == hybird2 ]]; then
#statements
hybird2
elif [[ $hybird_select_animo == hybird3 ]]; then
#statements
hybird3
fi
else
echo "You chose No. Exit status was $?."
fi
linux脚本编写图形,shell图形化界面脚本实现相关推荐
- 启动LINUX系统后,进入图形化界面的命令
1.进入xWindow的命令 $startx回车 或者修改/etc/inittab文件 cd /etc vi inittab 寻找: id:3:initdefault: 改为: id:5:initde ...
- Linux CentOS 6.x 关闭图形化界面的方法
vim /etc/inittab
- dubbo图形化界面搭建_使用 JMeter 进行 Dubbo 性能测试
1 前言 说道性能测试工具,你会立刻联想到哪一个?ab(ApacheBench).JMeter.LoadRunner.wrk-可以说市面上的压测工具实在是五花八门.那如果再问一句,对 Dubbo 进行 ...
- fedora mysql默认密码忘记_Linux fedora 24 忘记密码图形化界面修改root密码的方法
方法及其简单,只需要两步即可: 1.第一步: 打开终端,输入sudo su命令. –此处的密码为普通用户的密码,也就是开机时输入的密码. 2.第二步: 直接sudo passwd root就重置了ro ...
- linux远程图形操作系统,二、Linux操作系统之操作篇-Xmanager 远程访问Linux图形化界面...
2.Linux操作系统之操作篇-Xmanager 远程访问Linux图形化界面 红帽配置Xmanager 远程访问Linux: 1. 修改gdm配置文件,修改内容为粗体部分. /etc/gdm/cus ...
- 图形界面不卡的linux,图形化界面linux(linaro)的安装小结
描述 本文是在Xilinx官方给出的Zedboard上的Demo(linaro)基础上,并结合笔者的亲自实践,作出的一点小小的总结,希望能给"linux小白们"提供一些参考. 首先 ...
- 使用Putty+Xming登录Linux图形化界面
有些Linux程序需要依赖图形界面才能启动,例如Kettle的配置页面.之前都是使用VNC,通过在服务器和客户端分别安装VNCServer和VNCViewer来完成.今天介绍另外一种方式,在客户端利用 ...
- suse linux用户界面,suse linux开户图形化界面
suse linux开户图形化界面 (3页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 8.90 积分 1.root 登录,确保最下面的数字是 5:2./ ...
- centos运行java图形化界面_CentOS设置默认启动命令行(不启动图形界面)
CentOS中如何进入图形界面和文字界面,Linux真正的服务器是不会运行图形化界面的,怎么样才能在不卸载桌面的前提下开机直接进入命令界面呢?(我安装的是CentOS 6.5)下面就简单介绍以下: 一 ...
最新文章
- 机器学习 KNN算法实践
- elasticsearch6.2.2安装中文分词插件IK analyzer
- 【Go API 开发实战 5】基础1:启动一个最简单的 RESTful API 服务器
- 数据结构 线性链表栈
- oracle flash_cache,11gR2新特性之二 - Flash Cache 的SSD支持
- 一些非常值得人深思的段子 .
- C——结构体中的函数指针
- laravel下载安装
- Error:java.lang.RuntimeException: Some file crunching failed
- go import几种用法
- Android CoordinatorLayout Behavior
- 神马不是浮云,有未来就能改变世界
- Windows XP SP3安装教程(图)
- [Intellij IDEA] 通过学生认证免费激活IDEA
- 为虚拟机配置静态ip地址
- mysql什么方法返回id_MYSQL获取自增ID的四种方法
- Java笔记总结(一)
- 微信小程序云开发操作全解
- 【Unity】获取免费可商用的中文像素字体
- 纯原生JS的瀑布流插件Macy.js