我有一台远程OS X机器。它使用VPN软件(VPN Tracker)创建到服务器的隧道。我目前有一个Applescript来检查隧道是否打开;如果打开了,等待一分钟,然后再做一次;如果没有打开,运行命令将其激活。它工作得很好。
我已经编写了一个bash脚本,它将大量文件从远程站点发送到服务器。在大多数情况下,它工作得很好(每晚需要8+小时来发送大约10,000个文件),这是由cron计划的,无论出于何种目的,只需要几个tweeks(这是另一个问题)。
但是,我想在文件传输开始之前在脚本中添加一个网络检查,因为如果VPN没有启动,启动就没有意义了。我不是bash专家,在尝试编码之前,我想看看我的“逻辑”是否正确/正常。感谢您的任何建议,…。
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
发布于 2015-02-20 23:12:14
我稍微重新安排了一下,以避免查看VPN连接是否出现时的代码重复。
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
https://stackoverflow.com/questions/23112883
复制相似问题