Completing a timed get task with PowerShell

Source: Internet
Author: User

Recently, the company's website needs to be in the background to request and update data, but PHP is a back-end language, not automatically run, so a few ways to organize.

1, the front-end Timing Request page.

2, use batch processing.

3. Use Windows to schedule tasks.

The first option must be to open the browser, if the browser is closed, there may be problems, and the browser is open, a bit wasteful resources.

The second option is simple, just call the browser to open the page, but not the callback value.

So I'm going to use PowerShell to work with the scheduled task to do this.

We can use Win+r and then enter PowerShell, and then enter to open PS, but this method does not have the administrator's permission (in WIN10 will not be able to write to the file to C-drive), but does not affect the following command execution.

I used a invoke-webrequest command to execute the Web request, please enter Get-help invoke-webrequest for detailed usage of this command, or review MSDN.

The simple usage is as follows, a URI switch is required, a request address is sent, like this:

1 invoke-webrequest-uri "http://www.7cgcg.com/*/*.php"

The resulting output is as follows

1statuscode:2002 Statusdescription:ok3 Content:4 5                     ########################################################6Record Date: 2017-03-28 14:34:447Number of updates: 08 no video in transcoding needs to be queried.9 Tenrawcontent:http/1.1 200OK Onevary:accept-Encoding AKeep-alive:timeout=5, max=100 -connection:keep-Alive -content-length:159 theContent-type:text/html;charset=utf-8 -Date:tue, April 2017 06:34:43GMT - Server: ... - Forms: {} +Headers: {[Vary, accept-encoding], [Keep-alive, Timeout=5, max=100], [Connection, Keep-alive], [Content-length, 159]...} - Images: {} + inputfields: {} A Links: {} at Parsedhtml:system.__comobject -rawcontentlength:159

As you can see, statuscode is the content of 200,content.

Then you can use the Select-object command to choose the content of this property, this time we need a pipeline, the contents of the previous command is entered to the following command to process, this and batch processing is the same, using the | Symbol

1 " http://www.7cgcg.com/*/*.php " | Select-object-expandproperty Content

Get the output as follows

1 # ####################################################### 2 date of record: 2017-03-28 14:39:003 update: 04 There is no need to query for video in transcoding.

Then save the content to a file as a record, this side with the Out-file command, note plus-append append write switch, otherwise overwrite the file.

1 " http://www.7cgcg.com/*/*.php " | Select-object-expandproperty Content | Out-file -append d:\mts_log.txt

When you are finished, you can save the command as a PowerShell script file in the PS1 format, and a new scheduled task executes at timed intervals.

Completing a timed get task with PowerShell

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.