Ansible-roles icon indicating copy to clipboard operation
Ansible-roles copied to clipboard

linux 使用 os-check 巡检时报错check_linux.sh: line 41: -: -: syntax error: operand expected (error token is "-")

Open ansushl opened this issue 4 years ago • 5 comments

当我运行os-check 巡检后,生成的html文件报错 如图所示 image

具体报错: check_linux.sh: line 41: -: -: syntax error: operand expected (error token is "-") check_linux.sh: line 43: -: -: syntax error: operand expected (error token is "-")

操作系统 CentOS Linux release 7.9.2009 (Core)

ansushl avatar Apr 16 '22 09:04 ansushl

我查看了一下,发现是在检测inode时,被传入了一个非数值参数 “-”,导致-ge对比时由于不为数值报错的,可能需要在进行ge对比时校验下是否为数字

image

ansushl avatar Apr 17 '22 05:04 ansushl

感谢提醒,我加了个数字判断。你可以试试。

https://github.com/lework/Ansible-roles/blob/c1ef43cbb1e643d3aeca0d51bdcbacad2c12d748/os-check/files/check_linux.sh#L41

lework avatar Apr 18 '22 02:04 lework

加了判断没有生效,我加了个判断,你可以参考下

#  value=${2:-0}
  if [[ $2 =~ '\^[1-9]+\$' ]]; then
    value=${2}
  else
    value=0
  fi

ansushl avatar Apr 19 '22 05:04 ansushl

value=${2:-0}

if [[ $2 =~ '^[1-9]+$' ]]; then value=${2} else value=0 fi

试了下 这个 可以解决那个问题

srebro-cn avatar May 11 '22 06:05 srebro-cn

后面又重新看了下,这个还要考虑下有小数的情况,我这里又改了一版,你们试试。

https://github.com/lework/Ansible-roles/blob/24a53f6da7039f8183395cfc4d5985ce360a8d90/os-check/files/check_linux.sh#L41-L42

lework avatar May 12 '22 02:05 lework