当前位置: 技术问答>linux和unix
关于shell脚本中grep返回错误信息
来源: 互联网 发布时间:2017-05-19
本文导语: 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" ...
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
如题, 这个原因是为什么。应该怎么解决
|
建议减少管道的使用,比如:
top -n 3 | awk '/java.*irm/{print $1,$9}' >restorecpufile
jvmpid=`awk 'NR==1{print $1}' restorecpufile`
jvmcpu=`awk 'NR==1{print $2}' restorecpufile`
|
报什么错误
是不是$jvmpid 的值是空的。
是不是$jvmpid 的值是空的。