我目前有一个运行curl
函数的脚本来从另一台服务器获取文件,我正在尝试使用此脚本调试一些问题,并希望为此curl
函数启用日志记录。 / p>
我已经读过这可以使用--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
test文件夹包含服务器名称的文件夹,例如server2.contoso.com和server3.contoso.com
我已使用下面提供的建议更新了代码,现在出现错误
E:\ WebApps \ LogHarvest \ basic.vbs(94,3)(null):系统找不到文件s pecified。
第94,3行是:objShell.Run strcURL ,, true
' Build the cURL command line.
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) & " "
strcURL = strcURL & "http://" & strServer & "/weblogs/gr" & strShortYear & strMonth & strDay & ".zip"
'Echo to see strcURL
Wscript.Echo strcURL
echo返回
"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运行上述命令运行正常,表明脚本在其他地方失败。
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
答案 0 :(得分:0)
假设您的代码段正确(因为我不知道strCodeBase
,strServerDir
,strServer
,......变量的内容:
' 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
Resource:要获取有关curl执行操作的更多详细信息和信息,请尝试使用具有给定文件名的--trace
或--trace-ascii
选项进行登录,如下所示:
curl --trace trace.txt www.haxx.se