0

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.