【发布时间】:2015-02-12 03:30:03
【问题描述】:
我目前有一个运行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
测试文件夹包含具有服务器名称的文件夹,例如 server2.contoso.com 和 server3.contoso.com
我已经根据下面提供的建议更新了代码,我现在收到一个错误
E:\WebApps\LogHarvest\basic.vbs(94, 3) (null):系统找不到文件s 指定。
第 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
回声返回
"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
【问题讨论】:
-
您的问题主要是关于
curlhow-to,还是vbscripthow-to? -
我会说一个 vbscript 操作方法
-
wscript.echo strcURL的输出呢?拜托add examples to your question:看起来怎么样,应该怎么样。 -
这将运行 curl.exe contoso1.domain.com\w3svc01\gr150204.zip,它将文件 gr150204.zip 拉到当前文件夹中。一个 --trace 开关会给我类似 logfile.log 的东西,我希望 curl 在完成后将此函数写入日志文件,然后使用当前时间戳重命名该日志文件,以便在下次运行时不会被覆盖跨度>
-
对于不言自明的
The system cannot find the file specified消息,无需多言。 指定的文件很可能是curl.exe在"E:\WebApps\LogHarvest\curl-7.40.0-win32\bin\"目录下...Run期望提供的字符串与在命令行窗口中写入的字符串相同。