linux脚本编写图形,shell图形化界面脚本实现

  • Post author:
  • Post category:linux


#!/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_ent