我实现的如下功能:
假设局域网中有3台电脑A、B、C,我需要A、B2台电脑每天晚上2点自动开机(设置了BIOS自动唤醒,然后使用任务计划自动运行bat),将A机的a.txt 和 B机的b.txt 2个文本文件的内容都追加到C的一个共享文件夹中的C.txt中
这个功能很简单,我已实现了代码,但是我遇到个问题,就是不是每一次追加都是成功的,大概有40%左右的机率会失败,我在bat加入了ping 命,返回结果是通的
电脑启动后了,可以直接远程,证明网络确实是通的,但不知道为什么会出现失败,
不知道有哪位高人做过类似的功能,有没有遇到这样的情况?
以下是部分代码:
AUlog_server.txt 是C机上的文本文件,权限是 everyone 完全控制,B、C机文本的内容就是追加到此文本中。
AUlog_temp.txt 是A、B机本地的文本文件,内面的内容是前面的代码处理得来的。
AUlog_local.txt 是A、B机本地的文本文件,用途是:如果AUlog_temp.txt 追加到AUlog_server.txt 失败,就会改为追加在本地的AUlog_local.txt 中
- ping 10.10.43.45>>AUlog_local.txt
- ping -n 6 10.10.43.45>>AUlog_local.txt
- ping -n 6 10.10.43.45>>AUlog_local.txt
- type AUlog_temp.txt>>\\10.10.43.45\AUlog\AUlog_server.txt && echo 服务器日志同步:成功!>>\\10.10.43.45\AUlog\AUlog_server.txt && echo 服务器日志同步:成功!>>AUlog_temp.txt || echo 服务器日志同步:失败!>>AUlog_local.txt
- type AUlog_temp.txt >> AUlog_local.txt
- del AUlog_temp.txt
复制代码 下面是运行的结果(因为追加失败,所以结果在B、C机中的 AUlog_local.txt 内容):
Pinging 10.10.43.45 with 32 bytes of data:
Reply from 10.10.43.45: bytes=32 time=5ms TTL=64
Reply from 10.10.43.45: bytes=32 time=1ms TTL=64
Reply from 10.10.43.45: bytes=32 time<1ms TTL=64
Reply from 10.10.43.45: bytes=32 time=1ms TTL=64
Ping statistics for 10.10.43.45:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 5ms, Average = 1ms
Pinging 10.10.43.45 with 32 bytes of data:
Reply from 10.10.43.45: bytes=32 time=3ms TTL=64
Reply from 10.10.43.45: bytes=32 time=1ms TTL=64
Reply from 10.10.43.45: bytes=32 time=1ms TTL=64
Reply from 10.10.43.45: bytes=32 time=1ms TTL=64
Reply from 10.10.43.45: bytes=32 time=1ms TTL=64
Reply from 10.10.43.45: bytes=32 time=1ms TTL=64
Ping statistics for 10.10.43.45:
Packets: Sent = 6, Received = 6, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 3ms, Average = 1ms
Pinging 10.10.43.45 with 32 bytes of data:
Reply from 10.10.43.45: bytes=32 time=5ms TTL=64
Reply from 10.10.43.45: bytes=32 time=1ms TTL=64
Reply from 10.10.43.45: bytes=32 time<1ms TTL=64
Reply from 10.10.43.45: bytes=32 time=1ms TTL=64
Reply from 10.10.43.45: bytes=32 time<1ms TTL=64
Reply from 10.10.43.45: bytes=32 time=1ms TTL=64
Ping statistics for 10.10.43.45:
Packets: Sent = 6, Received = 6, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 5ms, Average = 1ms
服务器日志同步:失败! |