本文介绍了如何等待使用netcat的开放端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试用jenkins创建一个自定义dockerfile.我会等到8080端口打开,而不是用netcat做一个丑陋的"sleep 60",但是对bash脚本和netcat不太有信心.
I'm trying to do a custom dockerfile with jenkins on it. I would to wait until port 8080 is open instead of doing an ugly 'sleep 60' with netcat but in not very confident with bash scripts and netcat.
以下是我要执行的操作的示例:
Here is an example of what i'm trying to do:
#!/bin/bash
opened=0
while [ "$opened" == "0" ]; do
echo "Waiting jenkins to launch on 8080..."
nc -vz localhost 8080
done
echo "Jenkins launched"
推荐答案
您不能将netcat设置为等到某个端口打开后再等待,因此您必须添加部分内容以等待下一次检查.试试这个:
You can't set netcat to wait until some port is open, so you have to add part for waiting before next check is made. Try this:
#!/bin/bash
echo "Waiting jenkins to launch on 8080..."
while ! nc -z localhost 8080; do
sleep 0.1 # wait for 1/10 of the second before check again
done
echo "Jenkins launched"
这篇关于如何等待使用netcat的开放端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!