如何将命令的输出(输出是数字)与数字进行比较?尝试查看输出是否大于或等于1



我正在尝试运行一个脚本,该脚本本质上运行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]

允许输出文件以这种方式为数字。

最新更新