我遇到了一个bash脚本的问题。我的脚本启动了一个需要一些时间才能启动的服务器。为了应对长时间的启动,我加入了一个while循环来查询服务器是否已经运行。
while [ $running -eq 0 ]; do
echo "===" $response "===";
if [ "$response" == "" ] || [ "$response" == *"404 Not Found"* ]; then
sleep 1;
response=$(curl $ip:4502/libs/granite/core/content/login.html);
else
running=1;
fi
done
当退出循环时,$response等于字符串"404"。如果是这种情况,那么这个事物应该仍然在循环中,不是吗?似乎我的循环提前退出了。
乔
[[ ]]
是 Bash 的扩展功能,因此请确保脚本以#!/bin/bash
开头,而不是#!/bin/sh
。虽然有一些在纯 POSIX shell 语法中进行等效测试的方法,但它们并不像使用[[ ]]
那样简洁明了。 - Gordon Davisson=== <html><head><title> 404 Not Found </title>... ===
,+++ <html><head><title> 404 Not Found </title>... +++
, - Joe Andolinaecho "$response" > file
可以让你进行调查。 - that other guy