计划任务2008 R2 – cmd行需要unix utc时间 – 如何dynamic获取它?

这些论坛是伟大的,我希望得到一些帮助头痛我做了一个手动的过程,应该是比我发现它更容易自动化。

我有一个供应商应用程序的命令行工具,将上传应用程序的日志。 该工具只需要Unix UTC时间,我需要每天运行3到4次计划任务来上传应用程序日志。 我可能只是上传所有的日志,但这仍然是一个问题,因为我不知道如何在脚本中做到这一点。 所以我可以上传所有的日志,而不用担心只上传最新的日志。

该命令是在我开始下面的powershell脚本中,但是如果使用batch file我可以更容易地做到这一点,我只是试图避免添加像blat发送电子邮件,也不知道如何以获得任务结果在批处理脚本,这是我需要发送的电子邮件。

下面的“IEX”是完整的命令,这是我需要填充UTC时间的一天,如果比从上次计划的任务运行得到时间更容易,那么这是最安全的select。 然后最后的“1 1”是供应商所要求的为上传添加选项的参数。

如何填充日志上传的当前date和时间? 如果是每天上午12:01(东部)到下午11:59(东部)这样的时间,那应该没问题?

# "iex" is an alias for the invoke-expression cmd iex c:\path_to_exe\myprog.exe -a 1379300570 1379300570 1 1 # $? lets us know if the previous command was successful or not # $LASTEXITCODE gives us the exit code of the last Win32 exe execution if (!$? -OR $LASTEXITCODE -gt 0) { $smtpServer = "smtp.mydomain.com" $fromAddress = "[email protected]" $toAddress = "[email protected]" $subject = "FAILURE" $msgBody = "Trouble with Task" # Use these variables if auth for the SMTP server is required! $senderCreds = new-object System.Net.networkCredential $senderCreds.UserName = "senderusername" $senderCreds.Password = "senderpwd" $smtpClient = new-object Net.Mail.SmtpClient($smtpServer) $smtpClient.Credentials = $senderCreds $smtpClient.Send($fromAddress,$toAddress,$subject,$msgBody) } 

要将当前date/时间作为Unix时间戳记,请计算从unix时期开始以来经过的秒数:

 $Now = [DateTime]::UtcNow $Epoch = Get-Date -Year 1970 -Date 01/01 $unixTime = [int](New-TimeSpan $epoch $now).TotalSeconds 

要及时find两个特定实例(例如前一天的00:01 – 23:59):

 $StartTime = (Get-Date "00:01:00").AddDays(-1) $EndTime = (Get-Date "23:59:00").AddDays(-1) $Epoch = Get-Date -Year 1970 -Date 01/01 $unixStart = [int](New-TimeSpan $epoch $StartTime).TotalSeconds $unixEnd = [int](New-TimeSpan $epoch $EndTime).TotalSeconds iex("c:\path_to_exe\myprog.exe -a $unixStart $unixEnd 1 1")