在windows上为curl编写日志

在windows上为curl编写日志,curl,vbscript,Curl,Vbscript,我目前有一个脚本,它运行一个curl函数从另一台服务器获取文件,我正在尝试调试此脚本的一些问题,并希望为此curl函数启用日志记录 我已经了解到,这可以通过使用--trace文件开关来实现 有人能帮我把这个功能添加到下面的代码中吗 对于每个curl调用,日志必须是唯一的,可能使用日期/时间调用 脚本定义了以下变量: strCodeBase = "E:\WebApps\LogHarvest\curl-7.40.0-win32\bin\" strScriptSource = "LogHarvest.

我目前有一个脚本,它运行一个
curl
函数从另一台服务器获取文件,我正在尝试调试此脚本的一些问题,并希望为此
curl
函数启用日志记录

我已经了解到,这可以通过使用
--trace
文件开关来实现

有人能帮我把这个功能添加到下面的代码中吗

对于每个
curl
调用,日志必须是唯一的,可能使用日期/时间调用

脚本定义了以下变量:

strCodeBase = "E:\WebApps\LogHarvest\curl-7.40.0-win32\bin\"
strScriptSource = "LogHarvest.vbs"
strServerDir = "\\server.contoso.com\WebLogs\test\"

'  Determine current date, then calculate date-1 and separate Day, Month, and Year.
strDate = Date
strDate = DateAdd("d",-1,strDate)
strDay = Day(strDate)
strMonth = Month(strDate)
strYear = Year(strDate)

'  Get the two digit representation of the year.
strShortYear = Right(strYear,2)

'  For day numbers less than 10, append a leading 0.
If strDay < 10 Then
    strDay = "0" & strDay
End If

'  For month numbers less than 10, append a leading 0.
If strMonth < 10 Then
    strMonth = "0" & strMonth
End If
回声回来了

"E:\WebApps\LogHarvest\curl-7.40.0-win32\bin\curl" -s -f --trace trace20150211191943.log -o "\\server.contoso.com\WebLogs\test\server2.contoso.com\gr150210.zip" http://server2.contoso.com/weblogs/gr150210.zip
从cmd运行上述命令运行ok,表明脚本在其他地方失败

Private Function FunDateTime( byVal dtmDateTime)
' input: any value of (or convertible to) 'date' TypeName
' returns YYYYmmddHHmmss string (14 chars)
FunDateTime = YEAR( dtmDateTime) & _
  Right( "00" & Month( dtmDateTime), 2) & _
  Right( "00" & Day( dtmDateTime), 2) & _
  Right( "00" & Hour( dtmDateTime), 2) & _
  Right( "00" & Minute( dtmDateTime), 2) & _
  Right( "00" & Second( dtmDateTime), 2)
End Function
'
' Examples:
' FunDateTime(  Now) returns YYYYmmddHHmmss 
' FunDateTime( Date) returns YYYYmmdd000000, i.e. HHmmss   == 000000
' FunDateTime( Time) returns 18991230HHmmss, i.e. YYYYmmdd == 18991230
' FunDateTime(  365) returns 19001230000000, i.e. 365 days since above date
' FunDateTime( "xy") results to 'Type mismatch' runtime error

假设您的代码片段正确(因为我不知道
strCodeBase
strServerDir
strServer
,…变量的内容):

:要获取有关curl所做工作的更多详细信息,请尝试使用带有给定文件名的
--trace
--trace ascii
选项,如下所示:

    curl --trace trace.txt www.haxx.se

您的问题主要是关于
curl
how-to,还是关于
vbscript
how-to?我想说的是vbscript how-to
wscript.echo strcURL
的输出是什么?请:它看起来怎么样?它应该是怎样的。这将运行curl.exe contoso1.domain.com\w3svc01\gr150204.zip,这将把文件gr150204.zip拉到当前文件夹中。一个--trace开关会给我类似于logfile.log的东西,我想在它完成后将这个函数写到一个日志文件中,然后用当前的时间戳重命名这个日志文件,这样它就不会在下一次运行时被覆盖,更不用说这个自解释的
消息了,系统找不到指定的文件。指定的文件很可能位于
“E:\WebApps\LogHarvest\curl-7.40.0-win32\bin\”
目录下的
curl.exe
。。。
运行时
希望提供的字符串与在命令行窗口中写入的字符串相同。在codeJosefZ中,有重要的下划线
结尾,感谢您的回复。我尝试将您的代码添加到我的脚本中,它抛出以下错误:
code
logharvest.vbs(206,39)Microsoft VBScript编译eror:Syntaxerror
code
这是FunDateTime=YEAR(dtmDateTime)&1。请不要在注释中发布代码片段。它变得有点不可读,因为你可以看到你自己。2.没有人能帮助你不知道所有使用的变量内容(见我的答案)。有关这方面的帮助,请阅读。3.来自
Wscript.Echo strcURL
Josef的Post结果,我已经用缺少的变量更新了我的问题,我希望它现在更有意义,但是我无法获得Echo的输出,因为脚本在Echo之前失败
    -私有函数是否应位于curl代码之前?-而且,我相信curl语法应该是“curl domain--trace tracefile”,按照这个顺序。所有的
    函数都是
    <代码>结束函数
    定义代码可以放在脚本中的任何位置,但在下一个重要和关键的条件下:您不能在任何其他过程(例如
    Sub
    Property Get
    )中定义
    函数
    过程。否则,将出现Microsoft VBScript编译错误:语法错误。嗯
    '  Build the cURL command line.
    strTraceFile = "trace" & FunDateTime( Now) & ".txt"
    strcURL = chr(34) & strCodeBase & "curl" & chr(34) _
        & " -s -f --trace " & strTraceFile & " -o "
    strcURL = strcURL & chr(34) & strServerDir & strServer & "\gr" _
        & strShortYear & strMonth & strDay & ".zip" & chr(34) & " "
    'Echo to see strcURL
    Wscript.Echo strcURL 
    
    Private Function FunDateTime( byVal dtmDateTime)
    ' input: any value of (or convertible to) 'date' TypeName
    ' returns YYYYmmddHHmmss string (14 chars)
    FunDateTime = YEAR( dtmDateTime) & _
      Right( "00" & Month( dtmDateTime), 2) & _
      Right( "00" & Day( dtmDateTime), 2) & _
      Right( "00" & Hour( dtmDateTime), 2) & _
      Right( "00" & Minute( dtmDateTime), 2) & _
      Right( "00" & Second( dtmDateTime), 2)
    End Function
    '
    ' Examples:
    ' FunDateTime(  Now) returns YYYYmmddHHmmss 
    ' FunDateTime( Date) returns YYYYmmdd000000, i.e. HHmmss   == 000000
    ' FunDateTime( Time) returns 18991230HHmmss, i.e. YYYYmmdd == 18991230
    ' FunDateTime(  365) returns 19001230000000, i.e. 365 days since above date
    ' FunDateTime( "xy") results to 'Type mismatch' runtime error
    
        curl --trace trace.txt www.haxx.se