人生的旅途,唯有努力,才能收获幸运与幸福。
用shell写的小工具
上一篇 /
下一篇 2012-03-01 16:14:29
刚刚系统故障,把我半个小时的东西弄没了啊。好了,废话不多说,直接贴代码,是在没
心情再重新写一遍了,51testing的blog做的是在不怎么样啊。
#this is the try to make the service autosizing
#author:yanshaoli
#time: 2012-03-01
#temp_service =''
#if [ $1 = '' ] then
# echo 请输入你要重启的服务名
# exit
#end fi
#####先对服务名做处理#########
temp_service=`echo $1`
temp_service=`echo $temp_service|cut -c 0-11`
echo "要重启的服务名是:"$temp_service
temp_service=`cat ServiceList.txt|grep $temp_service|awk '{print $3}'|head -1`
########对进程名字做处理#######
temp_service=`echo $temp_service|cut -c 0-9`
temp_service=`echo "$temp_service""*"`
echo $temp_service
cd ~
cd bin
for temp_service in `ls $temp_service` ; do
temp_service=`echo ${temp_service#*/}`
echo 正在关闭服务....请耐心等待
echo " "
echo " "
tmshutdown -s $temp_service
echo 正在启动服务....请耐心等待
echo " "
echo " "
tmboot -s $temp_service
echo 服务已经启动成功
echo " "
done
echo 服务已经顺利重启。
给同事用了一下,感觉不是那么友好。她建议我修改下,主要有两点,参数判空,大小写自动识别。就这两点,下午做完任务刚好有时间,就修改了一下。贴了上来。这个判空的方法是我试过的最好用的一种,起码可以保证达到目的。至于大小写自动识别,说的是全大写或全小写的情况。很好,迟点打算在整个组里面推广,嘿嘿。
#this is the try to make the service autosizing
#author:yanshaoli
#time: 2012-03-01
#version 1.1 修改兼容参数输入为进程名/服务名,并对空参数情况做处理!
#####先对服务名做处理#########
temp_service=`echo $1`
if [ "X$temp_service" = "X" ]; then
echo 请输入你要重启的服务名:autoRestart 服务名/进程名
return
fi
temp_service=`echo $temp_service|cut -c 0-11`
echo "要重启的服务名是:"$temp_service
temp_service=`cat ServiceList.txt|grep $temp_service|awk '{print $3}'|head -1`
#如果输入的是进程名,直接重启,不再做其他处理
temp_proc=`echo "$temp_service"|LANG=C awk '{if($0~/[^a-z]/) print "1"}'`
if [ "X$temp_proc" != "X" ]; then
echo 正在关闭进程....请耐心等待
echo " "
echo " "
tmshutdown -s $1
echo 正在启动进程....请耐心等待
echo " "
echo " "
tmboot -s $1
echo 进程已经启动成功
echo " "
echo 进程已经顺利重启。
return
fi
相关阅读:
- CGI浏览器远程执行SHELL脚本 (hanhanjiang, 2011-3-30)
- Linux磁盘空间监控的Shell脚本 (smile665, 2011-6-04)
- 【转】linux shell 数组建立及使用技巧 (msnshow, 2011-6-14)
- 【转】shell工具 pv (pipe viewer) (msnshow, 2011-6-14)
- Linux Shell实现模拟多进程并发执行 (msnshow, 2011-6-14)
- shell实现监控服务器状态以及服务器自动切换 (msnshow, 2011-7-23)
- 【转】Linux资源监控Shell (msnshow, 2011-7-31)
- 记录Xen测试中的两个Shell脚本 (smile665, 2011-8-14)
- awk使用shell变量,shell获取awk中的变量值 (smile665, 2011-9-29)
- Linux的Shell编程 运行Shell程序的方法 (xin_晴, 2011-12-14)
收藏
举报
TAG:
shell