如何根据日期更改批处理文件中的参数值?
问题如下,
我必须从服务器检索日志,因为我制作了一个名为“getServerLog.bat”的“.bat”文件,该文件的作用是获取放置在服务器上的实际日志文件。即“getServerLog.bat”的内容包含服务器上实际日志文件存储的位置,但服务器上的日志文件具有以下名称格式“yyyy_mm_dd.stderrout.log”,例如今天的 2011_11_30.stderrout.log文件,并且该名称是自动生成的,因此在 bat 文件“getServerLog.bat”中,我必须参数化该名称,以便它始终检索最新文件。有关更明确的信息,这里是bat文件的内容
“C:\ Program Files(x86)\ WinSCP \ WinSCP.exe”/console /command“选项批处理打开”“选项确认关闭”“打开gtp:< em>gtp@10.72.141.68" "得到/home/gtp/installed/jetty-6.1.18/logs/2011_08_25.stderrout.log C:\Users\prpandey\Desktop\gtp.log" "exit"
我需要参数化最后一个变量 2011_08_25.stderrout .log 获取最新的记录或日志。请帮我解决这个问题。
提前致谢。
The problem is as follows
I have to retrieve logs from a server for that I have made a ".bat" file named "getServerLog.bat" what this file does is it fetches the actual log file that is placed on the server. i.e the contents of "getServerLog.bat" consists of the location on the server where the actual log file is stored but the log file on the server has the following name format "yyyy_mm_dd.stderrout.log" like 2011_11_30.stderrout.log for today's file and this name is autogenerated so in the bat file "getServerLog.bat" I have to parameterize the name so that it always retrieves the latest file. For more explicit information here are the contents of the bat file
"C:\Program Files (x86)\WinSCP\WinSCP.exe" /console /command "option batch on" "option confirm off" "open gtp:gtp@10.72.141.68" "get /home/gtp/installed/jetty-6.1.18/logs/2011_08_25.stderrout.log C:\Users\prpandey\Desktop\gtp.log" "exit"
I need to parameterize the last variable 2011_08_25.stderrout.log to get the latest record or logs. Please help me out regarding this problem.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尽管这看起来很简单,正如 @Burrus 已经表明的那样,但不同的日期格式使其变得非常困难。
另一种方法是使用 WMIC,在这篇文章的 SO 中显示,
将批处理脚本日期转换为变量
尝试此代码
Eventhough it seems pretty easy, as @Burrhus already showed, the different date formats make it very difficult.
An alternative method, using WMIC, is shown in this post here in SO,
Batch script date into variable
try this code
根据你的日期格式 - 我的是丹麦语 yy-mm-dddd 你可以这样做。
当然,这应该根据日期格式进行更改。
According to your dateformat - mine is danish yy-mm-dddd you could do like this.
Of course this should be altered according to the dateformat.
在我的系统上,Aacini 的代码在 ('DATE
如果我将其更改为('echo.%DATE%>NUL'),它会在稍后的某个地方失败(XP SP3)。关于为什么无论系统当前的日期格式如何该代码都应该工作的一些解释会很棒。
On my system Aacini's code failes at ('DATE
If I change it to ('echo.%DATE%>NUL') it fails somewhere later (XP SP3). Some explanation on why this code should work regardless the system's current date format would be awesome.