我正在尝试运行一个本质上运行 psg defunct | 的脚本wc -l
并根据输出是否大于或等于 1 给出输出。
但是,我无法让 -ge
标志发挥作用。我想知道是否有人对我做错了什么有任何意见,以及您是否可以帮助我纠正它。
这是当前脚本:
#!/bin/bash -x
export LANG="C"
#
# Created by Blake Smreker | b0s00dg
# Purpose is to assist users with defunct process tickets
#
#
menu ()
{
echo "What is the server name?"
read srvrname
badboi=$"$srvrname"
}
vars ()
{
psgwc=$"/u/bin/psg defunct | wc -l"
psgd=$"/u/bin/psg defunct"
die=$"/bin/kill -9 `psg defunct | awk '{print $3}'`"
belowmsg=$'echo The number of defunct processes is below threshold! Resolve the ticket and put the following in the ticket:'
abovemsg=$'echo There is more than 100 zombies! Getting you more information:'
}
connect ()
{
connectme="/usr/bin/dzdo -u oseho /bin/ssh -qo PreferredAuthentications=publickey root@$badboi"
}
main ()
{
${connectme} ". /u/data/environment; $psgwc"
if ${connectme} $psgwc -ge 1
then
$abovemsg
echo "Determine the owner of the below process. Then copy and paste the below, and send it to the team on Service Now."
echo "psg defunct | wc -l:"
${connectme} $psgwc
${connectme} $psgd
else
$belowmsg
echo "psg defunct | wc -l:"
${connectme} $psgwc
fi
}
menu
vars
connect
main
这是错误信息:
+ /usr/bin/dzdo -u oseho /bin/ssh -qo PreferredAuthentications=publickey root@oses4101 /u/bin/psg defunct '|' wc -l -ge 1
wc: illegal option -- g
usage: wc [-c | -m | -C] [-lw] [file ...]
似乎认为我放-ge
是我使用wc
的一部分。但是,当我尝试更正它时,它不起作用。
问题出在底部的 if 语句上。
最佳答案
将 psg 的输出置为 defunct | wc -l
到一个文件中,然后在 test
中使用该文件工作:
[ $(cat outputfile) -ge 1]
以这种方式允许输出文件是一个数字。
关于linux - 如何将命令的输出(输出为数字)与数字进行比较?尝试查看输出是否大于或等于 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51435945/