Cron problem sh file

  • Good day. I'd like to ask for advice. I have a SH script that I would like to run once in a while ..

    if I let it through SSH did what it has and everything works, but if it dam into crontab so does not work.

    Libreelec stable last with RPi3

    my listing looked like this:

    SSH login. write console "crontab -e"

    text to run "* * * * * /storage/.kodi/playlist/XX.sh"

    ctrl + o save and exit

    The script should get the pairing code from the address and write it to a file in the same directory. but via crontab the file is empty. via ssh command is all right.

    can you please advise it to work via crontab? or is there any other way to run scripts at a certain time?

  • Code
    */10 * * * * /usr/bin/bash /storage/playlists/playlist_01.sh

    Don't assume the cron environment knows where things are so state /path/to/shell in addition to /path/to/script ^

    Working?

  • not work... log on cron run script

    Code
    /storage/.kodi/playlist/tmobilego/login.sh: line 80: jq: not found
    bash: true: unknown operand
    /storage/.kodi/playlist/tmobilego/login.sh: line 101: jq: not found
    /storage/.kodi/playlist/tmobilego/login.sh: line 102: jq: not found
    /storage/.kodi/playlist/tmobilego/login.sh: line 103: jq: not found
    Access token and refresh token saved!
  • So once again .. via SSH script works smoothly and creates a token file. when used in cron the file is created but is empty.

    here is a script where the address is XXXX instead of real values, because of abuse.

    Thank you

    Code
    #! /bin/sh
    request="http://sledovanitv.cz/api/device-login?deviceId=XXXXXXX&password=XXXXXXXX&version=3.2.004&lang=cs&unit=default"
    json=$(wget -qO - ${request})
    status=$(echo ${json} | jq -r '.status')
    sessionid=$(echo ${json} | jq -r '.PHPSESSID')
    echo ${sessionid} > /storage/.kodi/playlist/sledovanitv/session.id

    Log:

    Code
    Mar 15 17:55:00 LibreELEC crond[269]: USER root pid 12198 cmd /usr/bin/bash /storage/.kodi/playlist/sledovanitv/session.sh
    Mar 15 17:55:00 LibreELEC crond[269]: /storage/.kodi/playlist/sledovanitv/session.sh: line 4: jq: not found
    Mar 15 17:55:00 LibreELEC crond[269]: /storage/.kodi/playlist/sledovanitv/session.sh: line 5: jq: not found

    crontab -e (write):

    Code
    */5 * * * * /usr/bin/bash /storage/.kodi/playlist/sledovanitv/session.sh
  • Well, it would seem you need to install the jq utility

    Code
    kodi:~ # which jq
    /storage/.kodi/addons/virtual.system-tools/bin/jq
    kodi:~ # jq
    jq - commandline JSON processor [version 1.6]

    Either that or -- and this is the more likely answer -- you need to specify a path in your script or just call jq with an absolute path name instead of relying on $PATH.

    That's where I would start if I were you.

    edit:

    I just read you said it works when you ssh to the box. That means the second answer I gave is almost certainly the correct one.

  • You can include the complete environment:

    Code
    */10 * * * * /usr/bin/sh -c ". /etc/profile;exec sh /storage/.kodi/playlist/sledovanitv/session.sh"