Error if I run my script from "scheduled jobs"

  • Hi everyone!

    I created a script that I will soon post in the guide section as soon as I finished all testing :)

    My latest issue is running it throught scheduled jobs.

    If I run it from cli using

    /home/Script/test.sh

    it works fine.

    If I run it from scheduled jobs I recieve this error:

    This is how I created the job:


    I don't get why if I run the script from cli it work while if I run it from cronjob I recieve an error.

    OMV\ExecException: Failed to execute command 'export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin; export LANG=C.UTF-8; export SHELL=/bin/sh; sudo --shell --non-interactive --user=root -- /home/Script/Restart_downloader.sh 2>&1' with exit code '2': /home/Script/Restart_downloader.sh: 7: /home/Script/Restart_downloader.sh: Syntax error: word unexpected (expecting ")") in /usr/share/openmediavault/engined/rpc/cron.inc:177Is this a OMV bug?

    Intel G4400 - Asrock H170M Pro4S - 8GB ram - Be Quiet Pure Power 11 400 CM - Nanoxia Deep Silence 4 - 6TB Seagate Ironwolf - RAIDZ1 3x10TB WD - OMV 5 - Proxmox Kernel

    • Offizieller Beitrag

    Scripts are run in a shell environment.


    It is possible that, unless you specified in the shebang what shell to use, the script is using another shell than the one you are using when you run the script from the cli. I am not sure what script scheduled tasks use by defalut? Possibly the default for the user that the script runs as? I have never tried to use scheduled tasks, so I don't know. I use crontab from the cli.


    For example, this shebang as the first line in the script make sure it runs in bash:


    #!/usr/bin/env bash


    ...and this in sh:


    #!/usr/bin/env sh


    And the syntax can vary a little between different shells. That might be why the script riuns OK from the cli but not as a scheduled job?


    In my experience some shells are not correctly setup in OMV. At least that was the case in OMV4. But it seems that bash was correctly setup. Try to set bash as the shell to use both for the user and in the script, unless you have good reasons to use some other shell and verify that it is correctly setup.

    Be smart - be lazy. Clone your rootfs.
    OMV 5: 9 x Odroid HC2 + 1 x Odroid HC1 + 1 x Raspberry Pi 4

  • I think you have to start your command with "sh " in cron.

    sh /home/Script/test.sh

    HP t630 Thin Cliënt (AMD Embedded G-Series GX-420GI | QuadCore | 8GB)
    7.0.5-1 (Sandworm) | 64 bit | pve-kernel-6.8 | omvextrasorg 7.0

  • #!/usr/bin/env bash

    Thanks! That line worked!!

    Tonight I'll prepare a post :)

    Intel G4400 - Asrock H170M Pro4S - 8GB ram - Be Quiet Pure Power 11 400 CM - Nanoxia Deep Silence 4 - 6TB Seagate Ironwolf - RAIDZ1 3x10TB WD - OMV 5 - Proxmox Kernel

  • I think you have to start your command with "sh " in cron.

    sh /home/Script/test.sh


    4 years later and you made my day :)


    thank you !! this worked for me !!

    7.0.4-2 (Sandworm) // ASRock J5040-ITX with Intel(R) Pentium(R) Silver J5040 CPU @ 2.00GHz // be quiet! ATX 500W (BN46) // 2x4GB Samsung M471A5244BB0-CRC

    Fractal Design Node 304 // 4-Port PCIE to SATA 3.0 ControllerCard // 1x 128GB SSD for OS and 2x 4TB, 1x 5TB and 3x 8TB HDD as one big fuse.mergerfs space (no need for raid parity)

Jetzt mitmachen!

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