{"id":21002505,"url":"https://github.com/pimatic/pimatic-shell-execute","last_synced_at":"2025-05-15T00:31:12.567Z","repository":{"id":13546871,"uuid":"16238801","full_name":"pimatic/pimatic-shell-execute","owner":"pimatic","description":"pimatic plugin for executing shell commands","archived":false,"fork":false,"pushed_at":"2019-05-12T16:57:29.000Z","size":92,"stargazers_count":3,"open_issues_count":0,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-15T23:12:13.986Z","etag":null,"topics":["command-execution","pimatic","pimatic-plugin","scripting","shell"],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pimatic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-25T20:04:57.000Z","updated_at":"2019-05-12T16:57:30.000Z","dependencies_parsed_at":"2022-09-06T05:21:54.987Z","dependency_job_id":null,"html_url":"https://github.com/pimatic/pimatic-shell-execute","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pimatic%2Fpimatic-shell-execute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pimatic%2Fpimatic-shell-execute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pimatic%2Fpimatic-shell-execute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pimatic%2Fpimatic-shell-execute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pimatic","download_url":"https://codeload.github.com/pimatic/pimatic-shell-execute/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225316758,"owners_count":17455310,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-execution","pimatic","pimatic-plugin","scripting","shell"],"created_at":"2024-11-19T08:18:57.444Z","updated_at":"2024-11-19T08:18:58.376Z","avatar_url":"https://github.com/pimatic.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"pimatic shell execute plugin\n=======================\nThis plugin let you define devices that execute shell commands. Additionally, it allows you\nto execute shell commands in rule actions. So you can define rules of the form:\n\n    if ... then execute \"some command\"\n\nConfiguration\n-------------\nYou can load the plugin by editing your `config.json` to include:\n\n    { \n       \"plugin\": \"shell-execute\"\n    }\n\nCommands are executed parallel by default. With the optional boolean attribute \n`sequential`set to `true` all shell commands are executed sequentially. This option \nshould be used mindfully it can dramatically slow down the execution of command and\nyield other side effects like execution timeouts. \n\n    { \n       \"plugin\": \"shell-execute\",\n       \"sequential\": true\n    }\n    \nOptionally, it is also possible to define the *shell* to be used to execute commands. By default, `'/bin/sh'` is \nused on UNIX, and `'cmd.exe'` on Windows. It is also possible to set the current working directory *(cwd)*. \nBy default, the current working directory of pimatic is used.\n\n    { \n       \"plugin\": \"shell-execute\",\n       \"shell\": \"/bin/bash\",\n       \"cwd\": \"/home/pi/scripts\"\n    }\n    \nBy default, processes which did not terminate with 15 seconds will be terminated forcefully. The\ntimeout value given in milliseconds can be set as shown below. Note, long running processes \nmay cause blocking situations in pimatic and may lockup system resources. \nIf you need to start long running processes, see section on Trouble Shooting below.\n\n    { \n       \"plugin\": \"shell-execute\",\n       \"timeout\": 20000\n    }\n\n\n### ShellSwitch Device\n\nDevices can be defined by adding them to the `devices` section in the config file.\nSet the `class` attribute to `ShellSwitch`. For example:\n\n    { \n      \"id\": \"light\",\n      \"name\": \"Lamp\",\n      \"class\": \"ShellSwitch\", \n      \"onCommand\": \"echo on \u003e /home/pi/switchState\",\n      \"offCommand\": \"echo off \u003e /home/pi/switchState\",\n      \"getStateCommand\": \"echo /home/pi/switchState\",\n      \"interval\": 10000,\n      \"forceExecution\": false\n    }\n\nIf the `getStateCommand` option is set and the `interval` option is set to a value greater than 0, \nthe `getStateCommand` is executed in this ms interval to update the state of the switch. \n\n### ShellSensor Device\n\nYou can define a sensor device with an attribute which gets \n updated with the output of shell command:\n\n    { \n      \"id\": \"temperature\",\n      \"name\": \"Room Temperature\",\n      \"class\": \"ShellSensor\", \n      \"attributeName\": \"temperature\",\n      \"attributeType\": \"number\",\n      \"attributeUnit\": \"°C\",\n      \"attributeAcronym\": \"Room\",\n      \"command\": \"echo 42.0\"\n    }\n\nIf you're running pimatic on a RaspberryPi, you can use the \n following sensors for a quick overview of your system health:\n\n    {\n      \"id\": \"wlan-strength\",\n      \"name\": \"WLAN Strength\",\n      \"class\": \"ShellSensor\",\n      \"attributeName\": \"wlan-strength\",\n      \"attributeType\": \"number\",\n      \"attributeUnit\": \"%\",\n      \"command\": \"iwconfig wlan0 | grep Signal | sed -n -e 's/^.*Signal level.\\\\([0-9]*\\\\).*/\\\\1/gp'\",\n      \"interval\": 15000\n    },\n    {\n      \"id\": \"mem-usage\",\n      \"name\": \"Memory Usage\",\n      \"class\": \"ShellSensor\",\n      \"attributeName\": \"mem-usage\",\n      \"attributeType\": \"number\",\n      \"attributeUnit\": \"MB\",\n      \"command\": \"free -m | awk '$5 ~ /[0-9.]+/ { print $3 }'\",\n      \"interval\": 60000\n    },\n    {\n      \"id\": \"disk-usage\",\n      \"name\": \"Disk Usage\",\n      \"class\": \"ShellSensor\",\n      \"attributeName\": \"disk-usage\",\n      \"attributeType\": \"number\",\n      \"attributeUnit\": \"%\",\n      \"command\": \"df | awk '/^\\\\/dev\\\\/root/ { printf \\\"%.1f\\\", ($3/$2)*100 }'\",\n      \"interval\": 300000\n    },\n    {\n      \"id\": \"cpu-temp\",\n      \"name\": \"CPU Temperature\",\n      \"class\": \"ShellSensor\",\n      \"attributeName\": \"cpu-temp\",\n      \"attributeType\": \"number\",\n      \"attributeUnit\": \"°C\",\n      \"command\": \"/opt/vc/bin/vcgencmd measure_temp | cut -d \\\"=\\\" -f2 | cut -d \\\"'\\\" -f1\",\n      \"interval\": 60000\n    }\n\n\n### ShellButtons Device\n\nYou can define a button device with buttons that trigger individual shell commands, \n eliminating the need for individual rules:\n\n    { \n      \"id\": \"tv-remote\",\n      \"name\": \"TV Remote\",\n      \"class\": \"ShellButtons\",\n      \"buttons\": [\n        {\n          \"id\": \"tv-power\",\n          \"text\": \"PWR\",\n          \"onPress\": \"irsend SEND_ONCE tvset KEY_POWER\",\n          \"confirm\": true\n        }\n      ]\n    }\n    \nThe given example shows the possibility to create an infrared remote in the pimatic frontend \n using the lirc plugin. The `onPress` command can be any bash command or file you may \n want to execute.\n\n### ShellPresenceSensor Device\n\nYou can define a presence sensor whose state gets updated with the output of shell command. In some\nuse cases the shell command may only detect an external device triggered a \"present\" event, but cannot \ndetect its absence. In such cases, when the`ShellPresenceSensor` is \"present\" it needs to be \nautomatically reset to \"absent\" after some time. For this you can set to `autoReset` property to true:\n\n    {\n      \"id\": \"presence\",\n      \"name\": \"NGINX Server\",\n      \"class\": \"ShellPresenceSensor\",\n      \"command\": \"pgrep nginx \u003e/dev/null \u0026\u0026 echo 1 || echo 0\",\n      \"autoReset\": false,\n      \"resetTime\": 10000\n    }\n\nFor device configuration options see the [device-config-schema](device-config-schema.coffee) file.\n\nTroubleshooting\n-------\n\n### Execution of Long Running Commands\n\nLong running commands should be avoided as they may block pimatic or yield errors when the `timeout` value\nin the plugin configuration is set to kill pending processes which is the default. \n\nIf you want to execute a long running command though, write a wrapper script which sends the command\n to the background. You can also use a wrapper command which detaches the process from\n the controlling terminal and send it to the background. \n  * Linux: `nohup \u003ccommand\u003e \u0026` or `nohup bash -c \"\u003ccommand1\u003e; \u003ccommand2\u003e\" \u0026` \n    if you need to execute multiple commands\n  * Windows: `start -b \u003ccommand\u003e` \n  \n  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpimatic%2Fpimatic-shell-execute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpimatic%2Fpimatic-shell-execute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpimatic%2Fpimatic-shell-execute/lists"}