批处理脚本2008的服务器上 - 如果平成功,则 [英] Batch Script on 2008 server - If Ping successful then

查看:126
本文介绍了批处理脚本2008的服务器上 - 如果平成功,则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个脚本,将检查计算机是否我的局域网上运行我的脚本的其余部分之前。这是一个使用的Robocopy 一个简单的备份脚本,但我会把它想输出基于它是否成功与否的文件。
这是我。

I am attempting to write a script that will check to see if a computer is on my LAN before running the rest of my script. It is a simple backup script using robocopy but I would like it to output a file based on whether it was successful or not. This is what I have.

set machine=userbox
ping -n 1 %machine% > nul
if errorlevel 1 goto BAD
goto GOOD
:GOOD
robocopy source destination
echo "backup complete" > c:\scripts\backupgood-%machine%.log
shutdown /s /m \\%machine% /t 600
goto END
:BAD
echo "Computer not on" > c:\scripts\%machine%-offline.log
:END

现在的脚本不检测系统是否打开与否,它是假设它是与脚本将继续仿佛机能够被ping通。

Right now the script is not detecting whether the system is on or not and it is assuming it is on and continues with the script as if the machine was able to be pinged.

有人能指出为什么错误是不及格或者有人有确定如果一个系统是在线的更好的方法。

Can someone point out why the error is not passing or perhaps someone has a better way of determining if a system is online.

先谢谢了。

推荐答案

您可能只是检查你的远程目录的presence:

You could just check for the presence of your remote directory:

IF EXIST "\\%machine%\Share\To\Check" (
    ECHO %machine% is available.
) ELSE (
    ECHO %machine% is not available.
)

这篇关于批处理脚本2008的服务器上 - 如果平成功,则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆