击:如何加强输出到一条线? [英] Bash: How to enforce output to one line?
本文介绍了击:如何加强输出到一条线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了下面的Nagios的检查,检查 / etc / fstab文件
的坐骑,并通过使用东风
检查他们被正确安装:
I wrote the following Nagios check, which checks /etc/fstab
for mounts and by using df
checks if they are mounted properly:
#!/bin/bash
# Check mounts based on /etc/fstab
grep="/bin/grep"
awk="/bin/awk"
df="/bin/df"
mounts=$($grep nfs /etc/fstab | $awk '{print $2}')
# Check if mounts exist
for mount in $mounts; do
$df | $grep $mount &>/dev/null
if [ "$?" -eq "0" ]; then
msg="Mount $mount is mounted!"
else
msg="Mount $mount is not mounted!"
fi
echo $msg
done
当我运行检查返回正确的结果:
When I run the check it returns a proper result:
[root@nyproxy5 ~]# ./check_mount.sh
Mount /proxy_logs is mounted!
Mount /proxy_dump is mounted!
Mount /sync_logs is mounted!
[root@nyproxy5 ~]#
但我想脚本的输出为1行而不是3行,怎么能实现?
我意识到脚本此刻编写方式不允许它,连摩X被安装的消息应该改变,但我有一个很难用逻辑。
But I want the output of the script to be 1 line rather than 3 lines, how can it be achieved? I realize that the way the script is written at the moment doesn't allow it, even the "Mount X is mounted" message should be changed, but I'm having a hard time with the logic.
在此先感谢
推荐答案
修改回声$味精
到呼应-n $味精
-n
选项将避免打印换行
这篇关于击:如何加强输出到一条线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文