• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
TRIGGERcmd
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Cannot execute shell scripts: Wrong json syntax?

Raspberry Pi
2
4
392
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R
    Riccardo Cereser
    last edited by Jun 6, 2022, 9:16 AM

    Hi, first of all I love this service. So thank you for building Triggercmd!

    Below 2 of my several attempts to triggers 2 scripts (they work if I launch them via SSH or the Rasbian GUI). It seems form the Triggercmd dashboard that the commands are running when triggered, and the reboot and shutdown ones actually do what they are supposed to. However, I have no luck running any shell scripts. I've also moved them from desktop to the root folder, but it didn't help. What can that be? Is it an issue with the syntax?

    [
      {"trigger":"Reboot","command":"shutdown -r","ground":"background","voice":"reboot","allowParams": "false"},
     {"trigger":"shutdown","command":"shutdown now","ground":"background","voice":"shutdown hours","allowParams": "false"},
     {"trigger":"Change numbers","command":"\/root\/key_stroke.sh","ground":"background","voice":"change numbers","allowParams": "false"},
     {"trigger":"Show hours","command":"\/root\/hours_launcher.sh","ground":"background","voice":"show hours","allowParams": "false"},
    
    ]
    
    [
      {"trigger":"Reboot","command":"shutdown -r","ground":"background","voice":"reboot","allowParams": "false"},
     {"trigger":"shutdown","command":"shutdown now","ground":"background","voice":"shutdown hours","allowParams": "false"},
     {"trigger":"Change numbers","command":"/root/key_stroke.sh","ground":"background","voice":"change numbers","allowParams": "false"},
     {"trigger":"Show hours","command":"/root/hours_launcher.sh","ground":"background","voice":"show hours","allowParams": "false"},
    
    ]
    
    R 1 Reply Last reply Jun 6, 2022, 9:36 PM Reply Quote 0
    • R
      Russ @Riccardo Cereser
      last edited by Jun 6, 2022, 9:36 PM

      @riccardo-cereser, the problem might be the comma on the last line. The last one can't have a comma. If it does, the agent will consider the json invalid and restore the previous version.

      I tested this one on my Raspberry Pi and it worked for me:

       {"trigger":"Change numbers","command":"/root/key_stroke.sh","ground":"background","voice":"change numbers","allowParams": "false"},
      

      This is my /root/key_stroke.sh script:

      #!/bin/bash
      echo Testing >> /tmp/test.log
      

      I see that it worked because my /tmp/test.log file gets another Testing line each time I run it using the Trigger button on the website.

      I made my /root/key_stroke.sh script executable using this command:

      chmod +x /root/key_stroke.sh
      

      Russell VanderMey

      R 1 Reply Last reply Jun 7, 2022, 10:22 PM Reply Quote 0
      • R
        Riccardo Cereser @Russ
        last edited by Jun 7, 2022, 10:22 PM

        @russ Thanks, actually the comma in the end is a typo I’ve added just in the code snippets of the post. I’ve moved the scripts in a different folder, and the problem persist if a place the full path. However I have a new finding: I cannot launch any of those scripts from the terminal unless I enter in the exact folder. If I enter the full path like in your example, I get a message that the file does not exist. If I enter in the folder and simply type the file name, it works.

        So I wonder how can I configure the JSON file to navigate to the folder and then run the script? Or anything else I could try ?

        R 1 Reply Last reply Jun 8, 2022, 8:58 PM Reply Quote 0
        • R
          Russ @Riccardo Cereser
          last edited by Jun 8, 2022, 8:58 PM

          @riccardo-cereser, please try adding this to your script:

          SCRIPTDIR=$(dirname "$0")
          cd $SCRIPTDIR
          

          That way you can specify the full path to your script in the commands.json file, and when your script runs, it will cd to the directory where your script is.

          Russell VanderMey

          1 Reply Last reply Reply Quote 0
          1 out of 4
          • First post
            1/4
            Last post