如何在Shell中通过脚本判断某个服务是否存在的解决方法
2008-09-02 14:15
841 查看
创建一个test.sh文件,通过chmod a+x test.sh设置该脚本可以执行
#!/bin/sh
#Filename: test.sh
mysqlsvr=mysql
exist=`chkconfig | grep $mysqlsvr`
if [ -n $exist ];then
echo "exist:
fi
然后执行test.sh的时候,在第五行总是出现提示: [:mysql: binary operator excepted
然后我修改实现脚本为如下,就可以
#!/bin/sh
#Filename: test.sh
if [ $# -lt 1 ];then
echo "please input server name."
exit 1
fi
chkconfig | grep $1 | {
while read svr status;
do
if [ $svr = $1 ];then
echo "server: $svr exist"
fi
done
}
执行: test.sh mysql 得到的结果为: server: mysql exist
#!/bin/sh
#Filename: test.sh
mysqlsvr=mysql
exist=`chkconfig | grep $mysqlsvr`
if [ -n $exist ];then
echo "exist:
fi
然后执行test.sh的时候,在第五行总是出现提示: [:mysql: binary operator excepted
然后我修改实现脚本为如下,就可以
#!/bin/sh
#Filename: test.sh
if [ $# -lt 1 ];then
echo "please input server name."
exit 1
fi
chkconfig | grep $1 | {
while read svr status;
do
if [ $svr = $1 ];then
echo "server: $svr exist"
fi
done
}
执行: test.sh mysql 得到的结果为: server: mysql exist
相关文章推荐
- 如何在shell脚本中判断文件或者文件夹是否存在?
- 如何在shell脚本中判断文件或者文件夹是否存在?
- 如何在shell脚本中判断文件或者文件夹是否存在?
- 如何通过shell脚本来检查或监控MYSQL数据库服务是否正常?
- 判断文件是否存在的shell脚本代码
- 通过JS,Jquery判断某个字符在一个字符串中是否存在的方法
- shell脚本判断进程是否存在,并重新启动
- Linux系统shell脚本判断变量文件目录:权限、是否存在、空值、相等
- Android 判断服务和进程是否存在方法
- Linux系统shell脚本判断变量文件目录:权限、是否存在、空值、相等
- 判断文件是否存在的shell脚本代码
- Shell脚本中判断输入变量或者参数是否为空的方法
- shell脚本循环判断进程是否存在
- JQuery判断HTML元素是否存在的两种解决方法
- shell脚本判断文件是否存在
- 如何通过PHP判断年份是否是闰年----两种方法
- shell脚本中判断文件是否存在
- shell 脚本判断文件是否存在
- 判断文件是否存在的shell脚本代码
- Shell实现判断进程是否存在并重新启动脚本