linux 脚本 返回信息,关于shell脚本中grep返回异常信息

关于shell脚本中grep返回错误信息

top -n 3 |grep java|grep irm |awk '{print $1,$9}' >restorecpufile

jvmpid=`awk 'NR==1{print}' restorecpufile | awk '{print $1}'`

jvmcpu=`awk 'NR==1{print}' restorecpufile | awk '{print $2}'`

if [ ${jvmcpu:-999} != "999"  ] && [ `echo  "${jvmcpu} >= ${LIMIT}" |bc`  -eq  1  ];then

echo "ooooooooo$jvmpid"

if [ ${jvmpid:-999} != "999" ];then

echo '$jvmpid' = $jvmpid

#ps -ef >~/jvmcpu/1111111

#       cat ~/jvmcpu/1111111 |fgrep $jvmpid >2222222

ps -ef|grep $jvmpid > jvmcpulog.out              #执行这句,会报错,提示grep:  不匹配的 [ 或 [^

#       kill -3 $jvmpid

if ((count++ == 10));then

filename=`date +%s`

#       tar -zcf ${filename}.tar  ~/jvmcpu/jvmcpulog.out

echo "xiaoxi"

count=0

echo " ">~/jvmcpu/jvmcpulog.out

fi

fi

#else

#       echo "OG "

fi

如题, 这个原因是为什么。应该怎么解决

------解决方案--------------------

报什么错误

是不是$jvmpid 的值是空的。

------解决方案--------------------

建议减少管道的使用,比如:

top -n 3

------解决方案--------------------

awk '/java.*irm/{print $1,$9}' >restorecpufile

jvmpid=`awk 'NR==1{print $1}' restorecpufile`

jvmcpu=`awk 'NR==1{print $2}' restorecpufile`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值