#!/bin/bash
CheckURL="http://www.baidu.com/" #自定义远程地址,访问状态为 200 时执行启动 ssh 命令。
STATUS_CODE=`curl -o /dev/null -m 5 --connect-timeout 5 -s -w %{http_code} $CheckURL`
if [ "$STATUS_CODE" = "200" ]; then
service sshd start
fi
我试了一直不行,后来我 ping 了一下,再执行就成功了,这是为何。没 ping 之前一直不成功。
CheckURL="http://www.baidu.com/" #自定义远程地址,访问状态为 200 时执行启动 ssh 命令。
STATUS_CODE=`curl -o /dev/null -m 5 --connect-timeout 5 -s -w %{http_code} $CheckURL`
if [ "$STATUS_CODE" = "200" ]; then
service sshd start
fi
我试了一直不行,后来我 ping 了一下,再执行就成功了,这是为何。没 ping 之前一直不成功。