Well, if your script is capable to send commands to the server (via RCON or similar), then you just need to send them all one by one.
However that could be really slow and not quite good. Because your script cannot have "back checks", the server will just make the command (or won't) and script won't have any info how (and when) it finished. So you will need to call the next command when you will be sure the previous one is completed. That can be really painful to construct (and if server lags, you need to probably manually check where it finished or start over again).
There is also another possible solution, but it needs some changes to your server. If you know anything about Bukkit/spigot servers capable running server-only plugins, then it will be easy for you, otherwise you should study something about it.
The thing is that there are already well-developed tools for mass changes in worlds, but you need Spigot server to run them.
That tool is WorldEdit, which is kind of superior in large scale building and changing of blocks.
However it is not comfortable with commands from console, it is mainly built as ingame (player position dependant) tool.
This plugin is well updated and have quite good documentation, you can try it. It will be definetly better than sending thousands of commands to your server directly.