批处理文件和Windows调度程序的简单示例
我需要创建一个批处理文件,它将每天将网络日志文件从网络服务器复制到本地桌面盒。
我是一名 Web 开发人员,但我想尝试学习创建批处理文件的过程,并且我认为使用 Windows 调度程序应该可以帮助我实现目标。
无论如何,我只是在寻找一个起点。
我了解批处理文件背后的前提(回显打印信息,命令导致 mkdir 或移动等操作),但一些直接的教程会很棒。
或者,甚至 devguru.com 或 4guysfromrolla.com 等参考指南也会有所帮助。
谢谢,
I need to create a batch file which will copy web log files from a web server to a local desktop box on daily frequency.
I'm a web developer, but I'd like to take a stab at learning the process for creating a batch file and I think using the windows scheduler should get me where I need to go.
In any case, I'm just looking for a jumping off point.
I understand the premise behind a batch file (echo to print info, commands to cause actions such as mkdir or move, etc), but some straight forward tutorials would be great.
Or even a reference guide such as devguru.com or 4guysfromrolla.com would be helpful.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建批处理文件相对简单。
只需像在命令 shell 中一样键入所需的命令,然后使用 .bat 扩展名保存文件即可。
这里有一个简单的示例,您可能会觉得有用。请注意,您可以使用任何编辑器来创建批处理文件,只要它以文本格式保存即可。
根据您使用的 Windows 版本,创建计划任务的过程略有不同:
编辑:对misteraiden 的答案进行一些后续处理。
本质上,您正在寻找的是脚本功能。有多种可用的工具。批处理文件是 Windows 支持的最简单的脚本形式。例如,您可以在 PowerShell 或 < a href="http://www.python.org/" rel="nofollow noreferrer">Python。两者都是更强大、更灵活的脚本语言。根据您的脚本的要求以及您想要学习的内容,它们可能更合适。
但是,如果您只想复制,最简单、最容易的起点就是批处理文件。
Creating a batch file is relatively straightforward.
Just type out the commands you want as you would in the command shell, and save the file with a .bat extension.
There's a simple example here that you may find useful. Note, you can use any editor to create your batch file, as long as it saves in a text format.
Depending on which version of Windows you're using, the process to create a scheduled task is slightly different:
Edit: A little followup on misteraiden's answer.
Essentially, what you're looking for is scripting functionality. There are a variety of tools available. A batch file is the simplest form of scripting that Windows supports. You could, for example, write scripts in PowerShell or Python. Both are more powerful and flexible scripting languages. Depending on what the requirements are for your script, and what you feel like learning, they may be more appropriate.
However, If all you want to do is a
copy
, the simplest, easiest place to start is a batch file.这有点偏题,但是使用 XML 构建解释器(例如 NAnt )可能会派上用场这里。对于您想要做的事情来说可能有点过头了,但是如果您现在学习它,您将能够在许多不同的地方应用它的用途。
您可以使用Windows Scheduler来触发构建,然后它将完成各种操作,例如删除、复制、登录网络共享。
然而,也许要了解这一点,您可能需要了解有关命令行和命令行编程的更多信息。
无论哪种方式,我建议您查看一些处理 的 NAnt 示例复制和其他基础等。
This is a little left-of-field, but using an XML build interpreter such as NAnt could come in handy here. Probably over-kill for what you are trying to do, but if you learn it now, you'll be able to apply it's uses in many different places.
You could use Windows Scheduler to trigger the build, which would then complete various operations such as deleting, copying, logging on to network shares.
However, perhaps to learn this you would probably need to learn more about the command line and command line programming.
Either way, I recommend you check out some of the NAnt examples that deal with copying and other basics etc..
我发现除了前面提到的 Microsoft 网站之外,最好的参考之一是: http://www .robvanderwoude.com/batchfiles.php 我一直在使用它来解决我遇到的许多问题,并一直使用它来了解更多信息。我认为既然您已经知道批处理文件如何工作的前提,那么这将适合您。
I found one of the best references other than the Microsoft website that was mentioned in an earlier is: http://www.robvanderwoude.com/batchfiles.php I have been using this for many of the issues I have had and have been using it to learn more. I think since you have the premise of how batch files work, this will work out will for you.