I'd like to create a file (e.g. script.sh) that will reside on the same server as my Magento 2 instance.
I'd like to be able to call a URL (e.g RunScript.php) that would in turn execute this script
Is this possible?
Thanks
Use the PHP command shell_exec().
This takes a bash command as input which is executed. In your case it would be something like this:
<?php // RunScript.php
echo shell_exec('sh script.sh'); // run script and show output
?>
https://www.php.net/manual/en/function.shell-exec.php
Do not do this!
This approach is highly discouraged as it has all kinds of security vulnerabilities. If the script.sh has an error or one too many rm calls it could break your server. Requiring this solution implies a severe design flaw.