如何解决Bash 脚本对话框输入框向我的文件添加了额外的字符
该脚本的目的是 ping 主机并测试端口连接。脚本的第一部分在我输入主机并成功 ping 的地方工作。我有下面的图片 My Input box with no space
我在尝试通过在输入框中输入 www.google.com 80 来测试与 nc 的端口连接时遇到问题。
Here is an example of when I'm seeing issues
因此,当我使用下面的端口进入主机时,我的 tmpfile.txt 中会出现什么。好像添加了额外的字符。
如何防止这种情况发生?
[root@docker-desktop home]# cat tmpfile.txt
www.google.com 80[root@docker-desktop home]#
这是我的脚本
#!/bin/bash
# script to troubleshoot an IP or Domain
INPUTBOX=${INPUTBOX=dialog}
TITLE="Default"
MESSAGE="Something to display"
XCOORD=10
YCOORD=20
# function start
funcDisplayInputBox () {
$INPUTBOX --title "$1" --inputbox "$2" "$3" "$4" 2>tmpfile.txt
}
# function stop
# function start
funcDisplayInfoBox () {
$INPUTBOX --cr-wrap --title "$1" --infobox "$2" "$3" "$4"
sleep "$5"
}
# function stop
# ping script start
clear
funcDisplayInputBox "Troubleshooter" "What device would you like to troubleshoot?" "10" "20"
if [ "`cat tmpfile.txt`" != "" ]; then
ping -c 5 "`cat tmpfile.txt`"
else
funcDisplayInputBox "Error!" "Please enter a IP or Domain" "10" "20"
fi
# if the ping is successfull spit out a success message
if [ "$?" -eq "0" ]; then
funcDisplayInfoBox "Success!" "We can ping the device" "10" "20" "5"
else
funcDisplayInfoBox "Error!" "Device unreachable" "10" "20" "5"
fi
rm -f tmpfile.txt
sleep 5
touch tmpfile.txt
# ping part ends here
# netcat part starts here
funcDisplayInputBox "Troubleshooter" "Can we connect to the Device over a specific port?" "10" "20"
if [ "`cat tmpfile.txt`" != "" ]; then
nc -v -w 5 "`cat tmpfile.txt`"
sleep 2
pkill -x nc
else
funcDisplayInputBox "Error!" "Please enter a IP or Domain and port" "10" "20"
fi
if [ "$?" -eq "0" ]; then
funcDisplayInfoBox "Success!" "We can connect to the device" "10" "20" "5"
else
funcDisplayInfoBox "Error!" "Device unreachable" "10" "20" "5"
exit 1
fi
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。