首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用于网络检查的Bash嵌套条件

用于网络检查的Bash嵌套条件
EN

Stack Overflow用户
提问于 2014-04-16 22:49:20
回答 1查看 153关注 0票数 0

我有一台远程OS X机器。它使用VPN软件(VPN Tracker)创建到服务器的隧道。我目前有一个Applescript来检查隧道是否打开;如果打开了,等待一分钟,然后再做一次;如果没有打开,运行命令将其激活。它工作得很好。

我已经编写了一个bash脚本,它将大量文件从远程站点发送到服务器。在大多数情况下,它工作得很好(每晚需要8+小时来发送大约10,000个文件),这是由cron计划的,无论出于何种目的,只需要几个tweeks(这是另一个问题)。

但是,我想在文件传输开始之前在脚本中添加一个网络检查,因为如果VPN没有启动,启动就没有意义了。我不是bash专家,在尝试编码之前,我想看看我的“逻辑”是否正确/正常。感谢您的任何建议,…。

代码语言:javascript
运行
复制
if [ try remote IP (ping data center 192.168.x.x) ]; then
    move on to the rest of the script

elif [ (ping data center does not work) try general internet connection (telnet or ping) ]; then    

    # general internet connection is up
    if [ check "VPN script" (if the process is running) ]; then
        if [ wait 1 minute to see if it kicks the tire to get the VPN connection up ]; then
            if it works and reconnects (ping) -  move on to the rest of the script
        else
            if not (ping) send an email to support that there is a problem
            then exit the script
        fi
    else (if "VPN script" process is not running)
        try to start it
                if [ it starts and connection comes up (ping) ]; then
                    move on to the rest of the script
                elif [ it starts and connection does not come up (ping)  ]; then
                    send an email that there is a problem
                    exit the script
                else
                    [ it does not start ]; then
                    send an email that there is a problem
                    exit the script
                fi
    fi

else (general internet connection is not up)
    exit the script

fi

谢谢--Rich

EN

回答 1

Stack Overflow用户

发布于 2015-02-20 23:12:14

我稍微重新安排了一下,以避免查看VPN连接是否出现时的代码重复。

代码语言:javascript
运行
复制
if [ try remote IP (ping data center 192.168.x.x) ]; then
    move on to the rest of the script

elif [(ping data center does not work) try general internet connection (telnet or ping)]
then    

    # general internet connection is up
    if [ check "VPN script" (if "VPN script" process is not running) ]; then
        try to start it
        if [ it does not start ]; then
            send an email that there is a problem
            exit the script
        fi
    fi
    if [ wait 1 minute to see if it kicks the tire to get the VPN connection up ]; then
        if it works and reconnects (ping) -  move on to the rest of the script
    else
        if not (ping) send an email to support that there is a problem
        then exit the script
    fi

else (general internet connection is not up)
    exit the script

fi
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23112883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档