繁体   English   中英

Bash脚本将从数字中读取数字并运行命令(如果数字等于或大于X值)

[英]Bash script that will read a number from file and run command if number equals or is higher than X value

我希望有一个脚本从文件中读取一个数字,如果该数字等于或大于某个特定值,它将运行另一个命令,否则,脚本将死,这将是这样的:

[root@firewall ~]# cat result.txt 
50
[root@firewall ~]# 
[root@firewall ~]# ./run.sh
result.txt is higher or equals 50. Running /sbin/reboot
[root@firewall ~]# 

谢谢你的帮助。

#!/bin/bash

THRESHOLD=50
VALUE=$(cat result.txt)

# -eq -> equals
# -gt -> greater than
# -ge -> greater than or equal (you are looking for this one)

if [ $VALUE -ge $THRESHOLD ]
then
  # Your action
fi

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM