Call the url using wget and return ERRORLEVEL depending on the contents of the url

The client has its own Windows-based server on which they edit the contents of the CMS. Data is synchronized at night with the web server. This is a temporary solution for a slow internet connection.

Two things can be synchronized: new files (already sorted) and mySQL database. To do this, I write a script that exports the database to a dump file with mysqldumpand loads a dump.

The download process is performed using a third-party tool called ScriptFTP , an FTP automation tool.

Then I need to run the import based on a PHP script on the target server. Depending on this return value of the script, the ScriptFTP operation continues, and some directories are renamed.

I need an external tool for this, since scriptFTP only supports FTP calls. I was thinking about the Windows version of wget .

In scriptFTP, I can execute any batch or exe file, but I can only analyze the level of errors resulting from the call, not the output stdout. This means that I need to return errorlevel 1if the PHP import operation goes wrong, and errorlevel 0if everything goes well. In addition, it is obvious that I need to return a positive level of errors if the connection to the script import cannot be performed at all.

I have full control over the import of the PHP script and you can decide what it does with an error: display an error message, return the header, whatever.

How could you run wget (or any other server-side import tool) and return a certain level of error depending on what the PHP script returns?

It is best now to create a batch file that executes the wget command, saves the result in a file, and a batch file that returns an error level of 0 or 1 depending on the contents of the file. But I do not know how to combine the contents of a file using batch programming.

+1
source share
1 answer

You can do the following in powershell:

$a = wget --quiet -O - www.google.com
$rc = $a.CompareTo("Your magic string")
exit $rc
+2

Source: https://habr.com/ru/post/1728081/


All Articles