脚本执行后显示带颜色提示



利用action 函数

1、在脚本开头调用系统函数库functions

. /etc/rc.d/init.d/functions

2、需要显示颜色的地方调用函数库中的action函数

其中如果是成功,则根据下面的用法使用

   action "xxxxxxxxxxxxxx" /bin/true

   xxx是你希望脚本执行后看到的成功的提示信息

其中如果是失败,则根据下面的用法使用

   action "xxxxxxxxxxxxxx" /bin/true

   xxx是你希望脚本执行后看到的失败的提示信息

   

 下面是一个简单测试本地80端口的脚本,用到action功能  

#################################################

#!/bin/sh

#port=`netstat -lnt|grep 80|wc -l`

 . /etc/rc.d/init.d/functions

proc=`ps -ef |grep http|grep -v grep |wc -l`

if [ $proc -lt 1 ]

   then

   action "Web is fail." /bin/false

   /application/apache/bin/apachectl start

   action "Web is OK." /bin/true

else

   action "Web is OK." /bin/true

fi

##################################################

效果显示

wKioL1YXWYKwGNEZAAIzAi7Z-cA222.jpg