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

1 Answer 1

1

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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.