人生的旅途,唯有努力,才能收获幸运与幸福。

用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


TAG: shell

 

评分:0

我来说两句

日历

« 2024-05-05  
   1234
567891011
12131415161718
19202122232425
262728293031 

我的存档

数据统计

  • 访问量: 1193
  • 日志数: 1
  • 建立时间: 2012-03-01
  • 更新时间: 2012-03-01

RSS订阅

Open Toolbar