Shell 使用bash延迟多次启动同一程序
我正在编写一个bash脚本来测试我的多连接TCP服务器。脚本应该启动客户端几次。以下是我迄今为止所做的工作:Shell 使用bash延迟多次启动同一程序,shell,server,client,sleep,Shell,Server,Client,Sleep,我正在编写一个bash脚本来测试我的多连接TCP服务器。脚本应该启动客户端几次。以下是我迄今为止所做的工作: #!/bin/bash toport=8601 for ((port = 8600; port < 8610; port++)); do client 10.xml & replace $port $toport -- "10.xml" #modifying the port in the xml file ((toport
#!/bin/bash
toport=8601
for ((port = 8600; port < 8610; port++));
do
client 10.xml &
replace $port $toport -- "10.xml" #modifying the port in the xml file
((toport=toport+1))
done
但由于某些原因,情况变得更糟,因为没有客户端能够再连接到服务器。你知道为什么吗?在你的脚本中,你是在后台运行客户端,并将sleep语句放在循环的末尾,像下面那样修改它,或者在前台而不是后台运行客户端
client 10.xml &
sleep 3
replace $port $toport -- "10.xml" #modifying the port in the xml file
((toport=toport+1))
#sleep 1
谢谢,成功了!:但是,在接受答案之前,我能请你解释一下为什么会这样吗?睡眠是如何在你放置它的地方工作的,而不是我放置它的地方?我在后台运行作业之后立即放置它,然后执行与作业相关的两条语句。因此,只有当作业在后台运行后立即进行睡眠时,它才会起作用。这也确保作业在后台运行。从睡眠1中删除。@agc否,我添加了,因为它不工作。我将编辑这个问题
client 10.xml &
sleep 3
replace $port $toport -- "10.xml" #modifying the port in the xml file
((toport=toport+1))
#sleep 1