如何使用正则expression式的字面数字

我正在编写一个脚本来curl网页和grep / sed / sort / tail,然后使用nagios退出代码进行监视。 我的bash脚本如下:

queue= curl -s 'site | grep -ohE 'READY":[0-9]+' |\ sed 's/READY"://' | sort -n | tail -1 if [[ $queue =~ [0-1] ]]; then echo "OK - $queue current jobs." exit 0 fi if [[ $queue =~ [2-3] ]]; then echo "WARNING - $queue current jobs in queue." exit 1 fi if [[ $queue =~ [4-100] ]]; then echo "CRITICAL - $queue current jobs in queue." exit 2 fi 

我遇到的问题是它返回任何以3开头的数字,例如警告。 3,30,300等,而不是3。

 WARNING - 39 current jobs in queue. 

警告应该只2-3个工作,其中关键应该是4-100个工作,并确定0-1。

我如何将数字范围设置为仅在单个数字上而不是多个数字退出?

不要使用正则expression式。 这些是数字,应该这样对待。

 if [ $queue -lt 2 ]; then echo "OK - $queue current jobs." exit 0 fi if [ $queue -lt 4 ]; then echo "Warning - $queue current jobs." exit 1 fi if [ $queue -ge 4 ]; then echo "CRITICAL" exit 2 fi 

-lt =less于; -ge =更大的平等, 在这里看到更多