Building a plugin and I am stuck at the executing a shell command, which makes no sense why is not working

  • Been banging my head trying to understand how building a plugin works, and I tell you is hard and that is because the documentation is old and not relevant anymore.


    Now I finally managed to get to the point where i actually need to execute some shell commands from the rpc file, yet the command that works well in cli refuses to be executed by rpc.


    So to give an example:


    I have a script in ~/scripts/myscript.sh
    This script has a method in it names runTest that accepts one argument.


    Running this command from terminal like this and works:


    source ~/scripts/myscript.sh && runtTest "blabla"


    Now if I try to run this command from rpc with the following code:


    $cmd = 'source ~/scripts/myscript.sh && runtTest "blabla"';
    $process = new \OMV\System\Process($cmd);
    $process->execute();But every darn time I get this error: Failed to execute command 'export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin; export LANG=C; source ~/scripts/myscript.sh && runtTest "blabla"' with exit code '127':




    Any suggestions ?

    • Offizieller Beitrag

    because the documentation is old and not relevant anymore.

    What documenation are you looking at? This guide should still work for most things - https://github.com/skyajal/diypluginguide3.x

    $cmd = 'source ~/scripts/myscript.sh && runtTest "blabla"';

    This isn't really a command and the tilda is telling it to use the executing user's home directory. I assume the script is in your home directory. You should always use a full path. And you should change your script to take arguments.

    omv 7.0.5-1 sandworm | 64 bit | 6.8 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.13 | compose 7.1.4 | k8s 7.1.0-3 | cputemp 7.0.1 | mergerfs 7.0.4


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • What documenation are you looking at? This guide should still work for most things - https://github.com/skyajal/diypluginguide3.x

    Was talking about this one DIY Plugin Development


    Didn't know about the other one as this is the one always first in all searches :))


    As for the ~ it is used for the root directory.


    I wanted to reuse some scripts that I already use and they have more than one method in them, but I expected to be able to execute scripts the same way I execute them in the terminal this is the part I don't get, terminal command works fine rpc command returns error...

    • Offizieller Beitrag

    Was talking about this one DIY Plugin Development

    Yep that is ancient. I will have you added to the dev forum. Then your search might turn up newer info :)

    As for the ~ it is used for the root directory.

    That would assume the script is being executed by the root user. If a command is executed with sudo, it won't resolve to /root/.


    I wanted to reuse some scripts that I already use and they have more than one method in them, but I expected to be able to execute scripts the same way I execute them in the terminal this is the part I don't get, terminal command works fine rpc command returns error...

    Normally, you can but sourcing does weird things and I would try to avoid multiple commands. Your user (or the root user) might have a different profile than the user executing the code.

    omv 7.0.5-1 sandworm | 64 bit | 6.8 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.13 | compose 7.1.4 | k8s 7.1.0-3 | cputemp 7.0.1 | mergerfs 7.0.4


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Well I managed to make any script work, it just took me a bit to realise how to make it work.


    Step 1, In your mkconf make a script file (my_script):




    Step 2 make script executable


    Code
    chmod +x my_script


    Step 3 run script from your rpc



    Code
    $cmd = new \OMV\System\Process("omv-mkconf", "my_script", escapeshellarg($params['argument_to_pass']) );
            $cmd->setRedirect2to1();
            $cmd->execute();


    Works like a charm :)) no I just created the first part of my theme changing plugin using the already built tool, so you can run it either via ssh or via the admin gui.


    If user are interested I can make some time and update the current tutorial on the forum on how to build a basic example plugin.

  • chente

    Hat das Thema geschlossen.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!