You don't need to write any custom Bitcoin scripts (in the Bitcoin scripting language) in order to automate creation of transactions. Don't waste your time with the former; just use the bitcoin-cli as shown by seoincorporation and invoke it from your shell script or whatever programming language you prefer.
Alternatively, you could use the Bitcoin Core RPC interface through JSON-RPC calls from any programming language:
https://developer.bitcoin.org/reference/rpc/index.html
For createrawtransaction, it would be:
Instead of curl, you can use your chosen programming language's preferred framework to build and send a POST request.