├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ ├── feature-request---new-table.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md ├── dependabot.yml └── workflows │ ├── golangci-lint.yml │ ├── registry-publish.yml │ ├── stale.yml │ ├── steampipe-anywhere.yml │ └── sync-labels.yml ├── .gitignore ├── .goreleaser.yml ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── config └── exec.spc ├── docs ├── LICENSE ├── index.md └── tables │ ├── exec_command.md │ └── exec_command_line.md ├── exec ├── connection_config.go ├── plugin.go ├── table_exec_command.go ├── table_exec_command_line.go └── utils.go ├── go.mod ├── go.sum └── main.go /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Steampipe version (`steampipe -v`)** 14 | Example: v0.3.0 15 | 16 | **Plugin version (`steampipe plugin list`)** 17 | Example: v0.5.0 18 | 19 | **To reproduce** 20 | Steps to reproduce the behavior (please include relevant code and/or commands). 21 | 22 | **Expected behavior** 23 | A clear and concise description of what you expected to happen. 24 | 25 | **Additional context** 26 | Add any other context about the problem here. 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Questions 4 | url: https://turbot.com/community/join 5 | about: GitHub issues in this repository are only intended for bug reports and feature requests. Other issues will be closed. Please ask and answer questions through the Steampipe Slack community. 6 | - name: Steampipe CLI Bug Reports and Feature Requests 7 | url: https://github.com/turbot/steampipe/issues/new/choose 8 | about: Steampipe CLI has its own codebase. Bug reports and feature requests for those pieces of functionality should be directed to that repository. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request---new-table.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request - New table 3 | about: Suggest a new table for this project 4 | title: Add table exec_ 5 | labels: enhancement, new table 6 | assignees: "" 7 | --- 8 | 9 | **References** 10 | Add any related links that will help us understand the resource, including vendor documentation, related GitHub issues, and Go SDK documentation. 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Example query results 2 |
3 | Results 4 | 5 | ``` 6 | Add example SQL query results here (please include the input queries as well) 7 | ``` 8 |
9 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "gomod" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | pull-request-branch-name: 13 | separator: "-" 14 | assignees: 15 | - "misraved" 16 | - "madhushreeray30" 17 | labels: 18 | - "dependencies" 19 | -------------------------------------------------------------------------------- /.github/workflows/golangci-lint.yml: -------------------------------------------------------------------------------- 1 | name: golangci-lint 2 | on: 3 | push: 4 | tags: 5 | - v* 6 | branches: 7 | - main 8 | pull_request: 9 | 10 | jobs: 11 | golangci_lint_workflow: 12 | uses: turbot/steampipe-workflows/.github/workflows/golangci-lint.yml@main 13 | -------------------------------------------------------------------------------- /.github/workflows/registry-publish.yml: -------------------------------------------------------------------------------- 1 | name: Build and Deploy OCI Image 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | jobs: 9 | registry_publish_workflow_ghcr: 10 | uses: turbot/steampipe-workflows/.github/workflows/registry-publish-ghcr.yml@main 11 | secrets: inherit 12 | with: 13 | releaseTimeout: 60m 14 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: Stale Issues and PRs 2 | on: 3 | schedule: 4 | - cron: "30 23 * * *" 5 | workflow_dispatch: 6 | inputs: 7 | dryRun: 8 | description: Set to true for a dry run 9 | required: false 10 | default: "false" 11 | type: string 12 | 13 | jobs: 14 | stale_workflow: 15 | uses: turbot/steampipe-workflows/.github/workflows/stale.yml@main 16 | with: 17 | dryRun: ${{ github.event.inputs.dryRun }} 18 | -------------------------------------------------------------------------------- /.github/workflows/steampipe-anywhere.yml: -------------------------------------------------------------------------------- 1 | name: Release Steampipe Anywhere Components 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | 9 | jobs: 10 | anywhere_publish_workflow: 11 | uses: turbot/steampipe-workflows/.github/workflows/steampipe-anywhere.yml@main 12 | secrets: inherit 13 | -------------------------------------------------------------------------------- /.github/workflows/sync-labels.yml: -------------------------------------------------------------------------------- 1 | name: Sync Labels 2 | on: 3 | schedule: 4 | - cron: "30 22 * * 1" 5 | workflow_dispatch: 6 | 7 | jobs: 8 | sync_labels_workflow: 9 | uses: turbot/steampipe-workflows/.github/workflows/sync-labels.yml@main 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Editor cache and lock files 2 | *.swp 3 | *.swo 4 | 5 | # Binaries for programs and plugins 6 | *.exe 7 | *.exe~ 8 | *.dll 9 | *.so 10 | *.dylib 11 | 12 | # Test binary, built with `go test -c` 13 | *.test 14 | 15 | # Output of the go coverage tool, specifically when used with LiteIDE 16 | *.out 17 | 18 | # Dependency directories (remove the comment below to include it) 19 | # vendor/ 20 | -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | # This is an example goreleaser.yaml file with some sane defaults. 2 | # Make sure to check the documentation at http://goreleaser.com 3 | before: 4 | hooks: 5 | - go mod tidy 6 | builds: 7 | - env: 8 | - CGO_ENABLED=0 9 | - GO111MODULE=on 10 | - GOPRIVATE=github.com/turbot 11 | goos: 12 | - linux 13 | - darwin 14 | 15 | goarch: 16 | - amd64 17 | - arm64 18 | 19 | id: "steampipe" 20 | binary: "{{ .ProjectName }}.plugin" 21 | flags: 22 | - -tags=netgo 23 | 24 | archives: 25 | - format: gz 26 | name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}" 27 | files: 28 | - none* 29 | checksum: 30 | name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS" 31 | algorithm: sha256 32 | changelog: 33 | sort: asc 34 | filters: 35 | exclude: 36 | - "^docs:" 37 | - "^test:" 38 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## v1.1.1 [2025-04-18] 2 | 3 | _Bug fixes_ 4 | 5 | - Fixed Linux AMD64 plugin build failures for `Postgres 14 FDW`, `Postgres 15 FDW`, and `SQLite Extension` by upgrading GitHub Actions runners from `ubuntu-20.04` to `ubuntu-22.04`. 6 | 7 | ## v1.1.0 [2025-04-17] 8 | 9 | _Dependencies_ 10 | 11 | - Recompiled plugin with Go version `1.23.1`. ([#51](https://github.com/turbot/steampipe-plugin-exec/pull/51)) 12 | - Recompiled plugin with [steampipe-plugin-sdk v5.11.5](https://github.com/turbot/steampipe-plugin-sdk/blob/v5.11.5/CHANGELOG.md#v5115-2025-03-31) that addresses critical and high vulnerabilities in dependent packages. ([#51](https://github.com/turbot/steampipe-plugin-exec/pull/51)) 13 | 14 | ## v1.0.0 [2024-10-22] 15 | 16 | There are no significant changes in this plugin version; it has been released to align with [Steampipe's v1.0.0](https://steampipe.io/changelog/steampipe-cli-v1-0-0) release. This plugin adheres to [semantic versioning](https://semver.org/#semantic-versioning-specification-semver), ensuring backward compatibility within each major version. 17 | 18 | _Dependencies_ 19 | 20 | - Recompiled plugin with Go version `1.22`. ([#40](https://github.com/turbot/steampipe-plugin-exec/pull/40)) 21 | - Recompiled plugin with [steampipe-plugin-sdk v5.10.4](https://github.com/turbot/steampipe-plugin-sdk/blob/develop/CHANGELOG.md#v5104-2024-08-29) that fixes logging in the plugin export tool. ([#40](https://github.com/turbot/steampipe-plugin-exec/pull/40)) 22 | 23 | ## v0.2.0 [2023-12-12] 24 | 25 | _What's new?_ 26 | 27 | - The plugin can now be downloaded and used with the [Steampipe CLI](https://steampipe.io/docs), as a [Postgres FDW](https://steampipe.io/docs/steampipe_postgres/overview), as a [SQLite extension](https://steampipe.io/docs//steampipe_sqlite/overview) and as a standalone [exporter](https://steampipe.io/docs/steampipe_export/overview). ([#27](https://github.com/turbot/steampipe-plugin-exec/pull/27)) 28 | - The table docs have been updated to provide corresponding example queries for Postgres FDW and SQLite extension. ([#27](https://github.com/turbot/steampipe-plugin-exec/pull/27)) 29 | - Docs license updated to match Steampipe [CC BY-NC-ND license](https://github.com/turbot/steampipe-plugin-exec/blob/main/docs/LICENSE). ([#27](https://github.com/turbot/steampipe-plugin-exec/pull/27)) 30 | 31 | _Dependencies_ 32 | 33 | - Recompiled plugin with [steampipe-plugin-sdk v5.8.0](https://github.com/turbot/steampipe-plugin-sdk/blob/main/CHANGELOG.md#v580-2023-12-11) that includes plugin server encapsulation for in-process and GRPC usage, adding Steampipe Plugin SDK version to `_ctx` column, and fixing connection and potential divide-by-zero bugs. ([#26](https://github.com/turbot/steampipe-plugin-exec/pull/26)) 34 | 35 | ## v0.1.1 [2023-10-04] 36 | 37 | _Dependencies_ 38 | 39 | - Recompiled plugin with [steampipe-plugin-sdk v5.6.2](https://github.com/turbot/steampipe-plugin-sdk/blob/main/CHANGELOG.md#v562-2023-10-03) which prevents nil pointer reference errors for implicit hydrate configs. ([#19](https://github.com/turbot/steampipe-plugin-exec/pull/19)) 40 | 41 | ## v0.1.0 [2023-10-02] 42 | 43 | _Dependencies_ 44 | 45 | - Upgraded to [steampipe-plugin-sdk v5.6.1](https://github.com/turbot/steampipe-plugin-sdk/blob/main/CHANGELOG.md#v561-2023-09-29) with support for rate limiters. ([#17](https://github.com/turbot/steampipe-plugin-exec/pull/17)) 46 | 47 | ## v0.0.4 [2023-09-29] 48 | 49 | _Breaking changes_ 50 | 51 | - Removed the `output` column in the `exec_command` table. This column has been replaced by the `stdout_output` and `stderr_output` columns. ([#13](https://github.com/turbot/steampipe-plugin-exec/pull/13)) 52 | 53 | _What's new?_ 54 | 55 | - Added `stdout_output` and `stderr_output` columns to the `exec_command` table. ([#13](https://github.com/turbot/steampipe-plugin-exec/pull/13)) 56 | - Added `stream` column to the `exec_command_line` table. ([#13](https://github.com/turbot/steampipe-plugin-exec/pull/13)) 57 | - Added plugin limiter `exec_global` with `MaxConcurrency` set to 15 in an effort to reduce abuse reports due to large number of concurrent remote connections. ([#13](https://github.com/turbot/steampipe-plugin-exec/pull/13)) 58 | 59 | _Bug fixes_ 60 | 61 | - Results from the `exec_command` table should now be consistent when using local and remote connections. ([#13](https://github.com/turbot/steampipe-plugin-exec/pull/13)) 62 | 63 | _Dependencies_ 64 | 65 | - Recompiled plugin with [steampipe-plugin-sdk v5.6.0](https://github.com/turbot/steampipe-plugin-sdk/blob/main/CHANGELOG.md#v560-2023-09-27) which adds support for rate limiters. ([#13](https://github.com/turbot/steampipe-plugin-exec/pull/13)) 66 | - Recompiled plugin with Go 1.21. ([#13](https://github.com/turbot/steampipe-plugin-exec/pull/13)) 67 | 68 | ## v0.0.3 [2023-08-11] 69 | 70 | _Bug fixes_ 71 | 72 | - Fixed the plugin to return an appropriate error message when the config file is missing required arguments. ([#7](https://github.com/turbot/steampipe-plugin-exec/pull/7)) 73 | 74 | ## v0.0.2 [2023-07-20] 75 | 76 | _Bug fixes_ 77 | 78 | - Fixed the incorrect github repository reference in `docs/index.md` file. 79 | 80 | ## v0.0.1 [2023-07-13] 81 | 82 | _What's new?_ 83 | 84 | - New tables added 85 | - [exec_command](https://hub.steampipe.io/plugins/turbot/exec/tables/exec_command) 86 | - [exec_command_line](https://hub.steampipe.io/plugins/turbot/exec/tables/exec_command_line) 87 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | STEAMPIPE_INSTALL_DIR ?= ~/.steampipe 2 | BUILD_TAGS = netgo 3 | install: 4 | go build -o $(STEAMPIPE_INSTALL_DIR)/plugins/hub.steampipe.io/plugins/turbot/exec@latest/steampipe-plugin-exec.plugin -tags "${BUILD_TAGS}" *.go 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![image](https://hub.steampipe.io/images/plugins/turbot/exec-social-graphic.png) 2 | 3 | # Exec Plugin for Steampipe 4 | 5 | Use SQL to run commands locally or on remote Linux and Windows hosts. Then get the result as a table. 6 | 7 | - **[Get started →](https://hub.steampipe.io/plugins/turbot/exec)** 8 | - Documentation: [Table definitions & examples](https://hub.steampipe.io/plugins/turbot/exec/tables) 9 | - Community: [Join #steampipe on Slack →](https://turbot.com/community/join) 10 | - Get involved: [Issues](https://github.com/turbot/steampipe-plugin-exec/issues) 11 | 12 | ## Quick start 13 | 14 | ### Install 15 | 16 | Download and install the latest Steampipe plugin: 17 | 18 | ```bash 19 | steampipe plugin install exec 20 | ``` 21 | 22 | Configure your [credentials](https://hub.steampipe.io/plugins/turbot/exec#credentials) and [config file](https://hub.steampipe.io/plugins/turbot/exec#configuration). 23 | 24 | Configure your credential details in `~/.steampipe/config/exec.spc`: 25 | 26 | ```hcl 27 | connection "exec" { 28 | plugin = "exec" 29 | 30 | protocol = "ssh" 31 | host = "my-remote-linux-host" 32 | user = "my-username" 33 | private_key = "~/.ssh/my-remote-linux-host.pem" 34 | } 35 | ``` 36 | 37 | Run steampipe: 38 | 39 | ```shell 40 | steampipe query 41 | ``` 42 | 43 | List disks on a Linux host 44 | 45 | ```sql 46 | select 47 | output 48 | from 49 | exec_command 50 | where 51 | command = 'df -h'; 52 | ``` 53 | 54 | ``` 55 | +------------------------------------------------------+ 56 | | output | 57 | +------------------------------------------------------+ 58 | | Filesystem Size Used Avail Use% Mounted on | 59 | | /dev/root 7.6G 3.4G 4.3G 44% / | 60 | | tmpfs 483M 0 483M 0% /dev/shm | 61 | | tmpfs 194M 872K 193M 1% /run | 62 | | tmpfs 5.0M 0 5.0M 0% /run/lock | 63 | | /dev/xvda15 105M 5.3M 100M 5% /boot/efi | 64 | | tmpfs 97M 4.0K 97M 1% /run/user/1001 | 65 | +------------------------------------------------------+ 66 | ``` 67 | 68 | ## Engines 69 | 70 | This plugin is available for the following engines: 71 | 72 | | Engine | Description 73 | |---------------|------------------------------------------ 74 | | [Steampipe](https://steampipe.io/docs) | The Steampipe CLI exposes APIs and services as a high-performance relational database, giving you the ability to write SQL-based queries to explore dynamic data. Mods extend Steampipe's capabilities with dashboards, reports, and controls built with simple HCL. The Steampipe CLI is a turnkey solution that includes its own Postgres database, plugin management, and mod support. 75 | | [Postgres FDW](https://steampipe.io/docs/steampipe_postgres/overview) | Steampipe Postgres FDWs are native Postgres Foreign Data Wrappers that translate APIs to foreign tables. Unlike Steampipe CLI, which ships with its own Postgres server instance, the Steampipe Postgres FDWs can be installed in any supported Postgres database version. 76 | | [SQLite Extension](https://steampipe.io/docs/steampipe_sqlite/overview) | Steampipe SQLite Extensions provide SQLite virtual tables that translate your queries into API calls, transparently fetching information from your API or service as you request it. 77 | | [Export](https://steampipe.io/docs/steampipe_export/overview) | Steampipe Plugin Exporters provide a flexible mechanism for exporting information from cloud services and APIs. Each exporter is a stand-alone binary that allows you to extract data using Steampipe plugins without a database. 78 | | [Turbot Pipes](https://turbot.com/pipes/docs) | Turbot Pipes is the only intelligence, automation & security platform built specifically for DevOps. Pipes provide hosted Steampipe database instances, shared dashboards, snapshots, and more. 79 | 80 | ## Developing 81 | 82 | Prerequisites: 83 | 84 | - [Steampipe](https://steampipe.io/downloads) 85 | - [Golang](https://golang.org/doc/install) 86 | 87 | Clone: 88 | 89 | ```sh 90 | git clone https://github.com/turbot/steampipe-plugin-exec.git 91 | cd steampipe-plugin-exec 92 | ``` 93 | 94 | Build, which automatically installs the new version to your `~/.steampipe/plugins` directory: 95 | 96 | ``` 97 | make 98 | ``` 99 | 100 | Configure the plugin: 101 | 102 | ``` 103 | cp config/* ~/.steampipe/config 104 | vi ~/.steampipe/config/exec.spc 105 | ``` 106 | 107 | Try it! 108 | 109 | ``` 110 | steampipe query 111 | > .inspect exec 112 | ``` 113 | 114 | Further reading: 115 | 116 | - [Writing plugins](https://steampipe.io/docs/develop/writing-plugins) 117 | - [Writing your first table](https://steampipe.io/docs/develop/writing-your-first-table) 118 | 119 | ## Open Source & Contributing 120 | 121 | This repository is published under the [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) (source code) and [CC BY-NC-ND](https://creativecommons.org/licenses/by-nc-nd/2.0/) (docs) licenses. Please see our [code of conduct](https://github.com/turbot/.github/blob/main/CODE_OF_CONDUCT.md). We look forward to collaborating with you! 122 | 123 | [Steampipe](https://steampipe.io) is a product produced from this open source software, exclusively by [Turbot HQ, Inc](https://turbot.com). It is distributed under our commercial terms. Others are allowed to make their own distribution of the software, but cannot use any of the Turbot trademarks, cloud services, etc. You can learn more in our [Open Source FAQ](https://turbot.com/open-source). 124 | 125 | ## Get Involved 126 | 127 | **[Join #steampipe on Slack →](https://turbot.com/community/join)** 128 | 129 | Want to help but don't know where to start? Pick up one of the `help wanted` issues: 130 | 131 | - [Steampipe](https://github.com/turbot/steampipe/labels/help%20wanted) 132 | - [Exec Plugin](https://github.com/turbot/steampipe-plugin-exec/labels/help%20wanted) 133 | -------------------------------------------------------------------------------- /config/exec.spc: -------------------------------------------------------------------------------- 1 | # Defines a local connection 2 | 3 | connection "exec_local" { 4 | plugin = "exec" 5 | 6 | # Working directory to use when running commands. 7 | # Default is the current directory where steampipe is running. 8 | working_dir = "." 9 | 10 | # Shell interpreter to use for local commands. 11 | # For example, to use bash: 12 | # interpreter = [ "/bin/bash", "-c" ] 13 | } 14 | 15 | # Additional example connection configs for different host types 16 | # Specific examples can also be found at https://hub.steampipe.io/plugins/turbot/exec 17 | 18 | # Defines a remote connection to a Linux host 19 | 20 | # connection "exec_linux" { 21 | # plugin = "exec" 22 | 23 | # Protocol for the connection, set ssh for Linux hosts. 24 | # protocol = "ssh" 25 | 26 | # Host to connect to, either an IP address or a hostname. 27 | # host = "my-remote-linux-host" 28 | 29 | # Optional - Port to connect to, defaults to 22 30 | # port = 22 31 | 32 | # Username for the remote host connection. 33 | # user = "ubuntu" 34 | 35 | # Credentials, either password or private_key. 36 | # password = "my_password" 37 | 38 | # private_key can be either a path to a private key file or the private key itself. 39 | # private_key = "~/.ssh/my-remote-linux-host.pem" 40 | 41 | # Optional - Proxy settings 42 | # Enables the plugin to connect to host through a HTTP proxy. 43 | # If username and password are not set, then it will try to connect to the proxy without authentication. 44 | 45 | # proxy_host = "127.0.0.1" 46 | # proxy_port = 8080 47 | # proxy_user_name = "my_proxy_user" 48 | # proxy_user_password = "proxy_password" 49 | 50 | # Optional - Bastion connection settings 51 | # Enables connecting to host through a bastion host. The plugin will connect to bastion_host first, and then connect from there to host. 52 | 53 | # bastion_user = "ec2-user" 54 | # bastion_host = "52.67.108.24" 55 | # bastion_port = 22 56 | # bastion_password = "my_password" 57 | # bastion_private_key = "~/.ssh/my-bastion-host.pem" 58 | # } 59 | 60 | # Defines a remote connection to a Windows host 61 | 62 | # The Windows host must have WinRM enabled and configured. 63 | # You can check links bellow for more information on how to configure WinRM: 64 | # https://learn.microsoft.com/en-us/windows/win32/winrm/installation-and-configuration-for-windows-remote-management 65 | # https://learn.microsoft.com/en-us/troubleshoot/windows-client/system-management-components/configure-winrm-for-https 66 | # connection "exec_windows" { 67 | # plugin = "exec" 68 | 69 | # Protocol for the connection, set winrm for Windows hosts. 70 | # protocol = "winrm" 71 | 72 | # Host to connect to, either an IP address or a hostname. 73 | # host = "18.228.214.45" 74 | 75 | # Optional - Port to connect to, defaults to 5985 76 | # port = 5986 77 | 78 | # Username for the remote host connection. 79 | # user = "Administrator" 80 | 81 | # Password for the remote host connection. 82 | # password = "rh=PM76t54nouv&dqwe3cNM7J1(*skZhh*" 83 | 84 | # Optional - WinrM over HTTPS instead of HTTP. Defaults to false 85 | # https = true 86 | 87 | # Optional - Ignore certificate for HTTPS connection. Defaults to false 88 | # insecure = true 89 | # } 90 | -------------------------------------------------------------------------------- /docs/LICENSE: -------------------------------------------------------------------------------- 1 | Attribution-NonCommercial-NoDerivatives 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 58 | International Public License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-NonCommercial-NoDerivatives 4.0 International Public 63 | License ("Public License"). To the extent this Public License may be 64 | interpreted as a contract, You are granted the Licensed Rights in 65 | consideration of Your acceptance of these terms and conditions, and the 66 | Licensor grants You such rights in consideration of benefits the 67 | Licensor receives from making the Licensed Material available under 68 | these terms and conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Copyright and Similar Rights means copyright and/or similar rights 84 | closely related to copyright including, without limitation, 85 | performance, broadcast, sound recording, and Sui Generis Database 86 | Rights, without regard to how the rights are labeled or 87 | categorized. For purposes of this Public License, the rights 88 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 89 | Rights. 90 | 91 | c. Effective Technological Measures means those measures that, in the 92 | absence of proper authority, may not be circumvented under laws 93 | fulfilling obligations under Article 11 of the WIPO Copyright 94 | Treaty adopted on December 20, 1996, and/or similar international 95 | agreements. 96 | 97 | d. Exceptions and Limitations means fair use, fair dealing, and/or 98 | any other exception or limitation to Copyright and Similar Rights 99 | that applies to Your use of the Licensed Material. 100 | 101 | e. Licensed Material means the artistic or literary work, database, 102 | or other material to which the Licensor applied this Public 103 | License. 104 | 105 | f. Licensed Rights means the rights granted to You subject to the 106 | terms and conditions of this Public License, which are limited to 107 | all Copyright and Similar Rights that apply to Your use of the 108 | Licensed Material and that the Licensor has authority to license. 109 | 110 | g. Licensor means the individual(s) or entity(ies) granting rights 111 | under this Public License. 112 | 113 | h. NonCommercial means not primarily intended for or directed towards 114 | commercial advantage or monetary compensation. For purposes of 115 | this Public License, the exchange of the Licensed Material for 116 | other material subject to Copyright and Similar Rights by digital 117 | file-sharing or similar means is NonCommercial provided there is 118 | no payment of monetary compensation in connection with the 119 | exchange. 120 | 121 | i. Share means to provide material to the public by any means or 122 | process that requires permission under the Licensed Rights, such 123 | as reproduction, public display, public performance, distribution, 124 | dissemination, communication, or importation, and to make material 125 | available to the public including in ways that members of the 126 | public may access the material from a place and at a time 127 | individually chosen by them. 128 | 129 | j. Sui Generis Database Rights means rights other than copyright 130 | resulting from Directive 96/9/EC of the European Parliament and of 131 | the Council of 11 March 1996 on the legal protection of databases, 132 | as amended and/or succeeded, as well as other essentially 133 | equivalent rights anywhere in the world. 134 | 135 | k. You means the individual or entity exercising the Licensed Rights 136 | under this Public License. Your has a corresponding meaning. 137 | 138 | 139 | Section 2 -- Scope. 140 | 141 | a. License grant. 142 | 143 | 1. Subject to the terms and conditions of this Public License, 144 | the Licensor hereby grants You a worldwide, royalty-free, 145 | non-sublicensable, non-exclusive, irrevocable license to 146 | exercise the Licensed Rights in the Licensed Material to: 147 | 148 | a. reproduce and Share the Licensed Material, in whole or 149 | in part, for NonCommercial purposes only; and 150 | 151 | b. produce and reproduce, but not Share, Adapted Material 152 | for NonCommercial purposes only. 153 | 154 | 2. Exceptions and Limitations. For the avoidance of doubt, where 155 | Exceptions and Limitations apply to Your use, this Public 156 | License does not apply, and You do not need to comply with 157 | its terms and conditions. 158 | 159 | 3. Term. The term of this Public License is specified in Section 160 | 6(a). 161 | 162 | 4. Media and formats; technical modifications allowed. The 163 | Licensor authorizes You to exercise the Licensed Rights in 164 | all media and formats whether now known or hereafter created, 165 | and to make technical modifications necessary to do so. The 166 | Licensor waives and/or agrees not to assert any right or 167 | authority to forbid You from making technical modifications 168 | necessary to exercise the Licensed Rights, including 169 | technical modifications necessary to circumvent Effective 170 | Technological Measures. For purposes of this Public License, 171 | simply making modifications authorized by this Section 2(a) 172 | (4) never produces Adapted Material. 173 | 174 | 5. Downstream recipients. 175 | 176 | a. Offer from the Licensor -- Licensed Material. Every 177 | recipient of the Licensed Material automatically 178 | receives an offer from the Licensor to exercise the 179 | Licensed Rights under the terms and conditions of this 180 | Public License. 181 | 182 | b. No downstream restrictions. You may not offer or impose 183 | any additional or different terms or conditions on, or 184 | apply any Effective Technological Measures to, the 185 | Licensed Material if doing so restricts exercise of the 186 | Licensed Rights by any recipient of the Licensed 187 | Material. 188 | 189 | 6. No endorsement. Nothing in this Public License constitutes or 190 | may be construed as permission to assert or imply that You 191 | are, or that Your use of the Licensed Material is, connected 192 | with, or sponsored, endorsed, or granted official status by, 193 | the Licensor or others designated to receive attribution as 194 | provided in Section 3(a)(1)(A)(i). 195 | 196 | b. Other rights. 197 | 198 | 1. Moral rights, such as the right of integrity, are not 199 | licensed under this Public License, nor are publicity, 200 | privacy, and/or other similar personality rights; however, to 201 | the extent possible, the Licensor waives and/or agrees not to 202 | assert any such rights held by the Licensor to the limited 203 | extent necessary to allow You to exercise the Licensed 204 | Rights, but not otherwise. 205 | 206 | 2. Patent and trademark rights are not licensed under this 207 | Public License. 208 | 209 | 3. To the extent possible, the Licensor waives any right to 210 | collect royalties from You for the exercise of the Licensed 211 | Rights, whether directly or through a collecting society 212 | under any voluntary or waivable statutory or compulsory 213 | licensing scheme. In all other cases the Licensor expressly 214 | reserves any right to collect such royalties, including when 215 | the Licensed Material is used other than for NonCommercial 216 | purposes. 217 | 218 | 219 | Section 3 -- License Conditions. 220 | 221 | Your exercise of the Licensed Rights is expressly made subject to the 222 | following conditions. 223 | 224 | a. Attribution. 225 | 226 | 1. If You Share the Licensed Material, You must: 227 | 228 | a. retain the following if it is supplied by the Licensor 229 | with the Licensed Material: 230 | 231 | i. identification of the creator(s) of the Licensed 232 | Material and any others designated to receive 233 | attribution, in any reasonable manner requested by 234 | the Licensor (including by pseudonym if 235 | designated); 236 | 237 | ii. a copyright notice; 238 | 239 | iii. a notice that refers to this Public License; 240 | 241 | iv. a notice that refers to the disclaimer of 242 | warranties; 243 | 244 | v. a URI or hyperlink to the Licensed Material to the 245 | extent reasonably practicable; 246 | 247 | b. indicate if You modified the Licensed Material and 248 | retain an indication of any previous modifications; and 249 | 250 | c. indicate the Licensed Material is licensed under this 251 | Public License, and include the text of, or the URI or 252 | hyperlink to, this Public License. 253 | 254 | For the avoidance of doubt, You do not have permission under 255 | this Public License to Share Adapted Material. 256 | 257 | 2. You may satisfy the conditions in Section 3(a)(1) in any 258 | reasonable manner based on the medium, means, and context in 259 | which You Share the Licensed Material. For example, it may be 260 | reasonable to satisfy the conditions by providing a URI or 261 | hyperlink to a resource that includes the required 262 | information. 263 | 264 | 3. If requested by the Licensor, You must remove any of the 265 | information required by Section 3(a)(1)(A) to the extent 266 | reasonably practicable. 267 | 268 | 269 | Section 4 -- Sui Generis Database Rights. 270 | 271 | Where the Licensed Rights include Sui Generis Database Rights that 272 | apply to Your use of the Licensed Material: 273 | 274 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 275 | to extract, reuse, reproduce, and Share all or a substantial 276 | portion of the contents of the database for NonCommercial purposes 277 | only and provided You do not Share Adapted Material; 278 | 279 | b. if You include all or a substantial portion of the database 280 | contents in a database in which You have Sui Generis Database 281 | Rights, then the database in which You have Sui Generis Database 282 | Rights (but not its individual contents) is Adapted Material; and 283 | 284 | c. You must comply with the conditions in Section 3(a) if You Share 285 | all or a substantial portion of the contents of the database. 286 | 287 | For the avoidance of doubt, this Section 4 supplements and does not 288 | replace Your obligations under this Public License where the Licensed 289 | Rights include other Copyright and Similar Rights. 290 | 291 | 292 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 293 | 294 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 295 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 296 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 297 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 298 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 299 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 300 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 301 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 302 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 303 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 304 | 305 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 306 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 307 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 308 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 309 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 310 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 311 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 312 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 313 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 314 | 315 | c. The disclaimer of warranties and limitation of liability provided 316 | above shall be interpreted in a manner that, to the extent 317 | possible, most closely approximates an absolute disclaimer and 318 | waiver of all liability. 319 | 320 | 321 | Section 6 -- Term and Termination. 322 | 323 | a. This Public License applies for the term of the Copyright and 324 | Similar Rights licensed here. However, if You fail to comply with 325 | this Public License, then Your rights under this Public License 326 | terminate automatically. 327 | 328 | b. Where Your right to use the Licensed Material has terminated under 329 | Section 6(a), it reinstates: 330 | 331 | 1. automatically as of the date the violation is cured, provided 332 | it is cured within 30 days of Your discovery of the 333 | violation; or 334 | 335 | 2. upon express reinstatement by the Licensor. 336 | 337 | For the avoidance of doubt, this Section 6(b) does not affect any 338 | right the Licensor may have to seek remedies for Your violations 339 | of this Public License. 340 | 341 | c. For the avoidance of doubt, the Licensor may also offer the 342 | Licensed Material under separate terms or conditions or stop 343 | distributing the Licensed Material at any time; however, doing so 344 | will not terminate this Public License. 345 | 346 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 347 | License. 348 | 349 | 350 | Section 7 -- Other Terms and Conditions. 351 | 352 | a. The Licensor shall not be bound by any additional or different 353 | terms or conditions communicated by You unless expressly agreed. 354 | 355 | b. Any arrangements, understandings, or agreements regarding the 356 | Licensed Material not stated herein are separate from and 357 | independent of the terms and conditions of this Public License. 358 | 359 | 360 | Section 8 -- Interpretation. 361 | 362 | a. For the avoidance of doubt, this Public License does not, and 363 | shall not be interpreted to, reduce, limit, restrict, or impose 364 | conditions on any use of the Licensed Material that could lawfully 365 | be made without permission under this Public License. 366 | 367 | b. To the extent possible, if any provision of this Public License is 368 | deemed unenforceable, it shall be automatically reformed to the 369 | minimum extent necessary to make it enforceable. If the provision 370 | cannot be reformed, it shall be severed from this Public License 371 | without affecting the enforceability of the remaining terms and 372 | conditions. 373 | 374 | c. No term or condition of this Public License will be waived and no 375 | failure to comply consented to unless expressly agreed to by the 376 | Licensor. 377 | 378 | d. Nothing in this Public License constitutes or may be interpreted 379 | as a limitation upon, or waiver of, any privileges and immunities 380 | that apply to the Licensor or You, including from the legal 381 | processes of any jurisdiction or authority. 382 | 383 | ======================================================================= 384 | 385 | Creative Commons is not a party to its public 386 | licenses. Notwithstanding, Creative Commons may elect to apply one of 387 | its public licenses to material it publishes and in those instances 388 | will be considered the “Licensor.” The text of the Creative Commons 389 | public licenses is dedicated to the public domain under the CC0 Public 390 | Domain Dedication. Except for the limited purpose of indicating that 391 | material is shared under a Creative Commons public license or as 392 | otherwise permitted by the Creative Commons policies published at 393 | creativecommons.org/policies, Creative Commons does not authorize the 394 | use of the trademark "Creative Commons" or any other trademark or logo 395 | of Creative Commons without its prior written consent including, 396 | without limitation, in connection with any unauthorized modifications 397 | to any of its public licenses or any other arrangements, 398 | understandings, or agreements concerning use of licensed material. For 399 | the avoidance of doubt, this paragraph does not form part of the 400 | public licenses. 401 | 402 | Creative Commons may be contacted at creativecommons.org. -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | organization: Turbot 3 | category: ["saas"] 4 | icon_url: "/images/plugins/turbot/exec.svg" 5 | brand_color: "#002342" 6 | display_name: "Exec" 7 | short_name: "exec" 8 | description: "Steampipe plugin to run & query shell commands on local and remote servers." 9 | og_description: "Run & query shell commands with SQL! Open source CLI. No DB required." 10 | og_image: "/images/plugins/turbot/exec-social-graphic.png" 11 | engines: ["steampipe", "sqlite", "postgres", "export"] 12 | --- 13 | 14 | # Exec + Steampipe 15 | 16 | Execute commands locally or on remote Linux and Windows hosts through SSH or WinRM. 17 | 18 | [Steampipe](https://steampipe.io) is an open-source zero-ETL engine to instantly query cloud APIs using SQL. 19 | 20 | For example: 21 | 22 | ```sql 23 | select 24 | output 25 | from 26 | exec_command 27 | where 28 | command = 'df -h'; 29 | ``` 30 | 31 | ``` 32 | +------------------------------------------------------+ 33 | | output | 34 | +------------------------------------------------------+ 35 | | Filesystem Size Used Avail Use% Mounted on | 36 | | /dev/root 7.6G 3.4G 4.3G 44% / | 37 | | tmpfs 483M 0 483M 0% /dev/shm | 38 | | tmpfs 194M 872K 193M 1% /run | 39 | | tmpfs 5.0M 0 5.0M 0% /run/lock | 40 | | /dev/xvda15 105M 5.3M 100M 5% /boot/efi | 41 | | tmpfs 97M 4.0K 97M 1% /run/user/1001 | 42 | +------------------------------------------------------+ 43 | ``` 44 | 45 | ## Documentation 46 | 47 | - **[Table definitions & examples →](/plugins/turbot/exec/tables)** 48 | 49 | ## Get started 50 | 51 | ### Install 52 | 53 | Download and install the latest Exec plugin: 54 | 55 | ```bash 56 | steampipe plugin install exec 57 | ``` 58 | 59 | ### Credentials 60 | 61 | | Item | Description | 62 | |-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 63 | | Credentials | Local connection does not require credentials. For Linux remote connections, the plugin supports SSH private key authentication or password. For Windows remote connections, the plugin supports password authentication. | 64 | | Permissions | As the connection to host relies on SSH or WinRM, the user must have the necessary permissions to connect to the host. | 65 | | Radius | Each connection represents a single Exec Installation. | 66 | | Resolution | 1. With configuration provided in connection in steampipe _**.spc**_ config file.
2. An exec.yaml file in a .exec folder in the current user's home directory _**(~/.exec/exec.yaml or %userprofile\.exec\exec.yaml)**_. | 67 | 68 | ### Configuration 69 | 70 | There are multiple ways to configure the plugin depending on the type of connection you want to use. Bellows are some examples of how to configure the most common connections. 71 | 72 | #### Local connection 73 | 74 | ```hcl 75 | connection "exec_local" { 76 | plugin = "exec" 77 | } 78 | ``` 79 | 80 | #### Remote Linux connection through SSH 81 | 82 | ```hcl 83 | connection "exec_remote_linux" { 84 | plugin = "exec" 85 | 86 | protocol = "ssh" 87 | host = "my-remote-linux-host" 88 | user = "my-username" 89 | private_key = "~/.ssh/my-remote-linux-host.pem" 90 | } 91 | ``` 92 | 93 | #### Remote Windows connection through WinRM 94 | 95 | ```hcl 96 | connection "exec_remote_windows" { 97 | plugin = "exec" 98 | 99 | protocol = "winrm" 100 | host = "18.228.214.45" 101 | port = 5985 102 | user = "Administrator" 103 | password = "rh=PM76t54nouv&dqwe3cNM7J1(*skZhh*" 104 | } 105 | ``` 106 | 107 | #### Remote Windows connection through WinRM ignoring certificate validation 108 | 109 | ```hcl 110 | connection "exec_remote_windows" { 111 | plugin = "exec" 112 | 113 | protocol = "winrm" 114 | host = "18.228.214.45" 115 | https = true 116 | port = 5986 117 | insecure = true 118 | user = "Administrator" 119 | password = "rh=PM76t54nouv&dqwe3cNM7J1(*skZhh*" 120 | } 121 | ``` 122 | 123 | #### Remote Linux connection through SSH with in-file private key 124 | 125 | ```hcl 126 | connection "exec_remote_linux" { 127 | plugin = "exec" 128 | 129 | protocol = "ssh" 130 | host = "my-remote-linux-host" 131 | user = "my-username" 132 | private_key = < Pro-tip: If you are going to use multiple interpreters, you can name the connection name to reflect the interpreter used. For example, `connection "exec_local_bash" { ... }` or `connection "exec_local_python" { ... }` etc. 277 | 278 | ## Limiting concurrent connections 279 | 280 | For each query (command) executed, this plugin opens a new SSH/WinRM connection. If you are running a lot of queries against the same host, these connection attempts may be seen as abusive activity. 281 | 282 | To reduce the chance of getting flagged, the plugin has a default `max_concurrency` limiter set to `15`. However, this limiter can be toggled by defining a `limiter` resource in your `exec.spc` configuration file: 283 | 284 | ```hcl 285 | connection "exec_local" { 286 | plugin = "exec" 287 | working_dir = "." 288 | } 289 | 290 | plugin "exec" { 291 | limiter "exec_global" { 292 | max_concurrency = 15 293 | } 294 | } 295 | ``` 296 | 297 | 298 | -------------------------------------------------------------------------------- /docs/tables/exec_command.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Steampipe Table: exec_command - Query Exec Commands using SQL" 3 | description: "Allows users to query Exec Commands, specifically the command execution details, providing insights into command outputs and potential anomalies." 4 | --- 5 | 6 | # Table: exec_command - Query Exec Commands using SQL 7 | 8 | The Exec Command is a feature that enables the execution of arbitrary commands in the context of the current session. It is a powerful tool that can be used to run scripts, utilities, and other command-line tasks. With Exec Command, you can execute commands and scripts in a secure, controlled environment, and capture the output for further processing or analysis. 9 | 10 | ## Table Usage Guide 11 | 12 | The `exec_command` table provides insights into the execution of arbitrary commands within the current session context. As a Systems Administrator, explore command-specific details through this table, including command outputs, exit codes, and associated metadata. Utilize it to uncover information about command execution, such as error messages, the duration of command execution, and the verification of command outputs. 13 | 14 | ## Examples 15 | 16 | ### Query JSON files on Linux host 17 | Explore the configuration of your Linux host to identify the URL of your Jenkins WAR file. This could be useful for troubleshooting or for confirming the source of your Jenkins installation. 18 | 19 | ```sql+postgres 20 | select 21 | _ctx ->> 'connection_name' as host, 22 | stdout_output::jsonb -> 'core' ->> 'url' as jekins_war_url 23 | from 24 | exec_command 25 | where 26 | command = 'cat jenkins-default.json'; 27 | ``` 28 | 29 | ```sql+sqlite 30 | select 31 | json_extract(_ctx, '$.connection_name') as host, 32 | json_extract(json(stdout_output), '$.core.url') as jekins_war_url 33 | from 34 | exec_command 35 | where 36 | command = 'cat jenkins-default.json'; 37 | ``` 38 | 39 | ### Query package.json dependencies on Linux host 40 | Explore the dependencies and their versions in your package.json file on a Linux host. This is useful to understand the versions of libraries your project is using, which can help in debugging or updating your project. 41 | 42 | ```sql+postgres 43 | select 44 | _ctx->>'connection_name' as host, 45 | dep.key as dependency, 46 | dep.value as version 47 | from 48 | exec_command, 49 | json_each_text(stdout_output::json->'dependencies') as dep(key, value) 50 | where 51 | command = 'cat package.json'; 52 | ``` 53 | 54 | ```sql+sqlite 55 | select 56 | json_extract(_ctx, '$.connection_name') as host, 57 | dep.key as dependency, 58 | dep.value as version 59 | from 60 | exec_command, 61 | json_each(json_extract(stdout_output, '$.dependencies')) as dep 62 | where 63 | command = 'cat package.json'; 64 | ``` 65 | 66 | ### List files on Linux host 67 | Explore the contents of a Linux host by listing all files within it. This can be useful for assessing the current file structure or identifying any unexpected or suspicious files. 68 | 69 | ```sql+postgres 70 | select 71 | _ctx ->> 'connection_name' as host, 72 | stdout_output 73 | from 74 | exec_command 75 | where 76 | command = 'ls -la'; 77 | ``` 78 | 79 | ```sql+sqlite 80 | select 81 | json_extract(_ctx, '$.connection_name') as host, 82 | stdout_output 83 | from 84 | exec_command 85 | where 86 | command = 'ls -la'; 87 | ``` 88 | 89 | ### List devices on Linux host 90 | Explore the connected devices on a Linux host system. This query is useful for system administrators who need to monitor the devices linked to their Linux servers. 91 | 92 | ```sql+postgres 93 | select 94 | _ctx ->> 'connection_name' as host, 95 | stdout_output 96 | from 97 | exec_command 98 | where 99 | command = 'lsblk'; 100 | ``` 101 | 102 | ```sql+sqlite 103 | select 104 | json_extract(_ctx, '$.connection_name') as host, 105 | stdout_output 106 | from 107 | exec_command 108 | where 109 | command = 'lsblk'; 110 | ``` 111 | 112 | ### List disks on Linux host 113 | Explore the disk usage on a Linux host to manage storage efficiently by identifying areas with high usage. This allows for proactive cleanup and allocation of resources, enhancing system performance. 114 | 115 | ```sql+postgres 116 | select 117 | _ctx ->> 'connection_name' as host, 118 | stdout_output 119 | from 120 | exec_command 121 | where 122 | command = 'df -h'; 123 | ``` 124 | 125 | ```sql+sqlite 126 | select 127 | json_extract(_ctx, '$.connection_name') as host, 128 | stdout_output 129 | from 130 | exec_command 131 | where 132 | command = 'df -h'; 133 | ``` 134 | 135 | ### List user accounts on Linux host 136 | Explore which user accounts exist on a Linux host to better manage system access and security. This can be particularly useful in maintaining control over who has access to your system and ensuring unauthorized users are not present. 137 | 138 | ```sql+postgres 139 | select 140 | _ctx ->> 'connection_name' as host, 141 | stdout_output 142 | from 143 | exec_command 144 | where 145 | command = 'cat /etc/passwd'; 146 | ``` 147 | 148 | ```sql+sqlite 149 | select 150 | json_extract(_ctx, '$.connection_name') as host, 151 | stdout_output 152 | from 153 | exec_command 154 | where 155 | command = 'cat /etc/passwd'; 156 | ``` 157 | 158 | ### Query host file on Linux host 159 | Explore the host file details on a Linux host to understand the mappings between domain names and IP addresses. This can help in troubleshooting network connectivity issues or verifying the correct setup of network services. 160 | 161 | ```sql+postgres 162 | select 163 | stdout_output, 164 | _ctx ->> 'connection_name' as host 165 | from 166 | exec_command 167 | where 168 | command = 'cat /etc/hosts'; 169 | ``` 170 | 171 | ```sql+sqlite 172 | select 173 | stdout_output, 174 | json_extract(_ctx, '$.connection_name') as host 175 | from 176 | exec_command 177 | where 178 | command = 'cat /etc/hosts'; 179 | ``` 180 | 181 | ### List processes on Linux host 182 | Explore the active processes on a Linux host to understand the system's performance and resource allocation. This can help in identifying potential bottlenecks or issues that might be affecting the system's efficiency. 183 | 184 | ```sql+postgres 185 | select 186 | _ctx ->> 'connection_name' as host, 187 | stdout_output 188 | from 189 | exec_command 190 | where 191 | command = 'ps -ef'; 192 | ``` 193 | 194 | ```sql+sqlite 195 | select 196 | json_extract(_ctx, '$.connection_name') as host, 197 | stdout_output 198 | from 199 | exec_command 200 | where 201 | command = 'ps -ef'; 202 | ``` 203 | 204 | ### Show hardware information on Linux host 205 | Analyze the hardware configuration of a Linux host to understand its components and specifications. This can be useful for system administrators who need to assess the current hardware setup or plan for upgrades. 206 | 207 | ```sql+postgres 208 | select 209 | _ctx ->> 'connection_name' as host, 210 | stdout_output 211 | from 212 | exec_command 213 | where 214 | command = 'lshw'; 215 | ``` 216 | 217 | ```sql+sqlite 218 | select 219 | json_extract(_ctx, '$.connection_name') as host, 220 | stdout_output 221 | from 222 | exec_command 223 | where 224 | command = 'lshw'; 225 | ``` 226 | 227 | ### Query configuration file for rsyslog on Linux host 228 | Gain insights into the configuration of the rsyslog service on a Linux host. This is useful for understanding the current logging settings and identifying any potential issues or misconfigurations. 229 | 230 | ```sql+postgres 231 | select 232 | _ctx ->> 'connection_name' as host, 233 | stdout_output 234 | from 235 | exec_command 236 | where 237 | command = 'cat /etc/rsyslog.conf'; 238 | ``` 239 | 240 | ```sql+sqlite 241 | select 242 | json_extract(_ctx, '$.connection_name') as host, 243 | stdout_output 244 | from 245 | exec_command 246 | where 247 | command = 'cat /etc/rsyslog.conf'; 248 | ``` 249 | 250 | ### Query host IP addresses on Linux host 251 | Explore which Linux hosts have specific IP addresses. This query is useful for network management and troubleshooting, allowing you to quickly identify which hosts are using which IP addresses. 252 | 253 | ```sql+postgres 254 | select 255 | _ctx ->> 'connection_name' as host, 256 | stdout_output 257 | from 258 | exec_command 259 | where 260 | command = 'ip addr' 261 | order by 262 | host; 263 | ``` 264 | 265 | ```sql+sqlite 266 | select 267 | json_extract(_ctx, '$.connection_name') as host, 268 | stdout_output 269 | from 270 | exec_command 271 | where 272 | command = 'ip addr' 273 | order by 274 | host; 275 | ``` 276 | 277 | ### List files on Windows host 278 | Explore the contents of a Windows host by listing all files present. This can be useful for auditing file contents or tracking down specific files. 279 | 280 | ```sql+postgres 281 | select 282 | _ctx ->> 'connection_name' as host, 283 | stdout_output 284 | from 285 | windows.exec_command 286 | where 287 | command = 'dir'; 288 | ``` 289 | 290 | ```sql+sqlite 291 | select 292 | json_extract(_ctx, '$.connection_name') as host, 293 | stdout_output 294 | from 295 | windows_exec_command 296 | where 297 | command = 'dir'; 298 | ``` 299 | 300 | ### List network info on Windows host 301 | Explore the network information on a Windows host to gain insights into the status and details of all active network connections. This can be useful for troubleshooting network issues or for routine network monitoring. 302 | 303 | ```sql+postgres 304 | select 305 | _ctx ->> 'connection_name' as host, 306 | stdout_output 307 | from 308 | windows.exec_command 309 | where 310 | command = 'ipconfig /all'; 311 | ``` 312 | 313 | ```sql+sqlite 314 | select 315 | json_extract(_ctx, '$.connection_name') as host, 316 | stdout_output 317 | from 318 | windows_exec_command 319 | where 320 | command = 'ipconfig /all'; 321 | ``` 322 | 323 | ### List disks on a local Mac OSX 324 | Explore the disk configuration of a local Mac OSX to gain insight into the system's storage setup. This is particularly useful for system administrators seeking to understand the disk utilization of their machines. 325 | 326 | ```sql+postgres 327 | select 328 | _ctx ->> 'connection_name' as host, 329 | stdout_output 330 | from 331 | exec_command 332 | where 333 | command = 'diskutil list'; 334 | ``` 335 | 336 | ```sql+sqlite 337 | select 338 | json_extract(_ctx, '$.connection_name') as host, 339 | stdout_output 340 | from 341 | exec_command 342 | where 343 | command = 'diskutil list'; 344 | ``` 345 | 346 | ### Handle failing commands 347 | Determine the areas in which commands are failing by analyzing the output of those commands. This can be especially useful for diagnosing and troubleshooting issues in your system. 348 | 349 | ```sql+postgres 350 | select 351 | _ctx ->> 'connection_name' as host, 352 | case 353 | when exit_code = 0 then stdout_output 354 | else stderr_output 355 | end as output 356 | from 357 | exec_command 358 | where 359 | command = 'ls non_existing_file'; 360 | ``` 361 | 362 | ```sql+sqlite 363 | select 364 | json_extract(_ctx, '$.connection_name') as host, 365 | case 366 | when exit_code = 0 then stdout_output 367 | else stderr_output 368 | end as output 369 | from 370 | exec_command 371 | where 372 | command = 'ls non_existing_file'; 373 | ``` 374 | 375 | ### Query network interfaces through Python interpreter on local machine 376 | This query allows you to pinpoint the specific network interfaces on your local machine using a Python interpreter. In a practical setting, this can be useful for identifying potential network issues or for understanding the configuration of your local machine's network interfaces. 377 | This example requires Python3 interpreter to be set on `exec.spc` file. Please refer [this](index.md#local-connection-using-a-specific-interpreter) on how to set it up. 378 | 379 | 380 | ```sql+postgres 381 | select 382 | index, 383 | name 384 | from 385 | exec_command, 386 | json_to_recordset(stdout_output::json) as x(index int, name text) 387 | where 388 | command = 'import json, socket; print(json.dumps([{"index": interface[0], "name": interface[1]} for interface in socket.if_nameindex()]))'; 389 | ``` 390 | 391 | ```sql+sqlite 392 | Error: SQLite does not support json_to_recordset function. 393 | ``` 394 | 395 | ### Query hostname through Perl interpreter on local machine 396 | Explore the system's hostname using the Perl interpreter on your local machine. This is useful for identifying the specific machine you're working on, especially in a networked environment with multiple machines. 397 | This example requires Perl interpreter to be set on `exec.spc` file. Please refer [this](index.md#local-connection-using-a-specific-interpreter) on how to set it up. 398 | 399 | 400 | ```sql+postgres 401 | select 402 | stdout_output as hostname 403 | from 404 | exec_command 405 | where 406 | command = 'use Sys::Hostname; my $hostname = hostname; print "$hostname\n";'; 407 | ``` 408 | 409 | ```sql+sqlite 410 | select 411 | stdout_output as hostname 412 | from 413 | exec_command 414 | where 415 | command = 'use Sys::Hostname; my $hostname = hostname; print "$hostname\n";'; 416 | ``` -------------------------------------------------------------------------------- /docs/tables/exec_command_line.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Steampipe Table: exec_command_line - Query Exec Command Lines using SQL" 3 | description: "Allows users to query Exec Command Lines, providing insights into command line execution results and potential issues." 4 | --- 5 | 6 | # Table: exec_command_line - Query Exec Command Lines using SQL 7 | 8 | Exec is a service that enables the execution of arbitrary commands on the local system. It provides a mechanism to run commands and scripts, and capture their output for further processing. Exec helps users perform system-level operations, diagnose issues, and automate tasks. 9 | 10 | ## Table Usage Guide 11 | 12 | The `exec_command_line` table provides insights into command line execution within the local system. As a system administrator or DevOps engineer, explore command-specific details through this table, including execution results, exit status, and associated metadata. Utilize it to uncover information about command execution, such as those with unexpected results, the status of executed commands, and the verification of command outputs. 13 | 14 | ## Examples 15 | 16 | ### List files on Linux host 17 | Explore the list of files on a Linux host to better manage your system resources and understand file distribution. This can be particularly useful for identifying unnecessary files that may be taking up valuable space. 18 | 19 | ```sql+postgres 20 | select 21 | _ctx ->> 'connection_name' as host, 22 | line 23 | from 24 | exec_command_line 25 | where 26 | command = 'ls -la' 27 | order by 28 | _ctx ->> 'connection_name', 29 | line_number; 30 | ``` 31 | 32 | ```sql+sqlite 33 | select 34 | json_extract(_ctx, '$.connection_name') as host, 35 | line 36 | from 37 | exec_command_line 38 | where 39 | command = 'ls -la' 40 | order by 41 | json_extract(_ctx, '$.connection_name'), 42 | line_number; 43 | ``` 44 | 45 | ### List files on Linux host and show the stream used for output 46 | This query is used to analyze the output stream from a specific command executed on a Linux host. It can help in identifying any potential issues or errors that occurred during the execution of the command. 47 | 48 | ```sql+postgres 49 | select 50 | _ctx ->> 'connection_name' as host, 51 | line, 52 | stream 53 | from 54 | exec_command_line 55 | where 56 | command = 'ls non_existing_file' 57 | order by 58 | _ctx ->> 'connection_name', 59 | line_number; 60 | ``` 61 | 62 | ```sql+sqlite 63 | select 64 | json_extract(_ctx, '$.connection_name') as host, 65 | line, 66 | stream 67 | from 68 | exec_command_line 69 | where 70 | command = 'ls non_existing_file' 71 | order by 72 | json_extract(_ctx, '$.connection_name'), 73 | line_number; 74 | ``` 75 | 76 | ### List devices on Linux host 77 | This query allows you to analyze the devices connected to a Linux host. It's particularly useful for understanding the composition of your hardware resources and managing them effectively. 78 | 79 | ```sql+postgres 80 | select 81 | _ctx ->> 'connection_name' as host, 82 | line 83 | from 84 | exec_command_line 85 | where 86 | command = 'lsblk' 87 | order by 88 | _ctx ->> 'connection_name', 89 | line_number; 90 | ``` 91 | 92 | ```sql+sqlite 93 | select 94 | json_extract(_ctx, '$.connection_name') as host, 95 | line 96 | from 97 | exec_command_line 98 | where 99 | command = 'lsblk' 100 | order by 101 | json_extract(_ctx, '$.connection_name'), 102 | line_number; 103 | ``` 104 | 105 | ### List disks on Linux host 106 | Explore which disks are available on a Linux host to gain insights into storage usage and capacity. This information can help you manage your storage resources more effectively. 107 | 108 | ```sql+postgres 109 | select 110 | _ctx ->> 'connection_name' as host, 111 | line 112 | from 113 | exec_command_line 114 | where 115 | command = 'df -h' 116 | order by 117 | _ctx ->> 'connection_name', 118 | line_number; 119 | ``` 120 | 121 | ```sql+sqlite 122 | select 123 | json_extract(_ctx, '$.connection_name') as host, 124 | line 125 | from 126 | exec_command_line 127 | where 128 | command = 'df -h' 129 | order by 130 | json_extract(_ctx, '$.connection_name'), 131 | line_number; 132 | ``` 133 | 134 | ### List user accounts on Linux host 135 | Explore the user accounts present on a Linux host to gain a comprehensive understanding of who has access to the system. This is useful for auditing purposes and ensuring only authorized users have access. 136 | 137 | ```sql+postgres 138 | select 139 | _ctx ->> 'connection_name' as host, 140 | line 141 | from 142 | exec_command_line 143 | where 144 | command = 'cat /etc/passwd' 145 | order by 146 | _ctx ->> 'connection_name', 147 | line_number; 148 | ``` 149 | 150 | ```sql+sqlite 151 | select 152 | json_extract(_ctx, '$.connection_name') as host, 153 | line 154 | from 155 | exec_command_line 156 | where 157 | command = 'cat /etc/passwd' 158 | order by 159 | json_extract(_ctx, '$.connection_name'), 160 | line_number; 161 | ``` 162 | 163 | ### Query host file on Linux host 164 | Analyze the host file on a Linux host to understand the static hostname-to-IP mappings. This is useful for troubleshooting network issues and verifying the correct resolution of hostnames. 165 | 166 | ```sql+postgres 167 | select 168 | _ctx ->> 'connection_name' as host, 169 | line 170 | from 171 | exec_command_line 172 | where 173 | command = 'cat /etc/hosts' 174 | order by 175 | _ctx ->> 'connection_name', 176 | line_number; 177 | ``` 178 | 179 | ```sql+sqlite 180 | select 181 | json_extract(_ctx, '$.connection_name') as host, 182 | line 183 | from 184 | exec_command_line 185 | where 186 | command = 'cat /etc/hosts' 187 | order by 188 | json_extract(_ctx, '$.connection_name'), 189 | line_number; 190 | ``` 191 | 192 | ### List processes on Linux host 193 | Explore the active processes across various Linux hosts. This is particularly useful for system administrators to monitor and manage system processes, ensuring optimal performance and security. 194 | 195 | ```sql+postgres 196 | select 197 | _ctx ->> 'connection_name' as host, 198 | line 199 | from 200 | exec_command_line 201 | where 202 | command = 'ps -ef' 203 | order by 204 | _ctx ->> 'connection_name', 205 | line_number; 206 | ``` 207 | 208 | ```sql+sqlite 209 | select 210 | json_extract(_ctx, '$.connection_name') as host, 211 | line 212 | from 213 | exec_command_line 214 | where 215 | command = 'ps -ef' 216 | order by 217 | json_extract(_ctx, '$.connection_name'), 218 | line_number; 219 | ``` 220 | 221 | ### Show hardware information on Linux host 222 | Discover detailed hardware information on your Linux host. This query helps you gain insights into your system's hardware configuration, which can be beneficial for troubleshooting, system upgrades, or general maintenance. 223 | 224 | ```sql+postgres 225 | select 226 | _ctx ->> 'connection_name' as host, 227 | line 228 | from 229 | exec_command_line 230 | where 231 | command = 'lshw' 232 | order by 233 | _ctx ->> 'connection_name', 234 | line_number; 235 | ``` 236 | 237 | ```sql+sqlite 238 | select 239 | json_extract(_ctx, '$.connection_name') as host, 240 | line 241 | from 242 | exec_command_line 243 | where 244 | command = 'lshw' 245 | order by 246 | json_extract(_ctx, '$.connection_name'), 247 | line_number; 248 | ``` 249 | 250 | ### List user accounts on Linux host by parsing /etc/passwd file into columns 251 | Explore which user accounts exist on a Linux host and gain insights into their configuration details, such as whether they have a password, their user and group IDs, and their home directory and shell settings. This is useful for understanding the security and organization of your Linux system. 252 | 253 | ```sql+postgres 254 | select 255 | host, 256 | split_output[1] as username, 257 | case when split_output[2] = 'x' then true else false end as has_password, 258 | split_output[3] as user_id, 259 | split_output[4] as group_id, 260 | split_output[5] as user_comment, 261 | split_output[6] as home_directory, 262 | split_output[7] as shell 263 | from 264 | ( 265 | select 266 | _ctx ->> 'connection_name' as host, 267 | string_to_array(line, ':') as split_output 268 | from 269 | exec_command_line 270 | where 271 | command = 'cat /etc/passwd' 272 | order by 273 | _ctx ->> 'connection_name', 274 | line_number 275 | ) 276 | subquery; 277 | ``` 278 | 279 | ```sql+sqlite 280 | Error: SQLite does not support split or string_to_array functions. 281 | ``` 282 | 283 | ### List elevated commands ran on Linux host (/var/log/auth.log) 284 | Identify instances where elevated commands were run on a Linux host. This is useful for security auditing and detecting potentially malicious activities. 285 | Ref: https://regex101.com/r/ImwoFl/3 286 | 287 | 288 | ```sql+postgres 289 | select 290 | matches[1] as month, 291 | matches[2] as day, 292 | matches[3] as hour, 293 | matches[4] as hostname, 294 | matches[7] as pwd, 295 | matches[8] as elevated_user, 296 | matches[9] as command 297 | from 298 | ( 299 | select 300 | regexp_matches(line, '^(\S{3})? {1,2}(\S+) (\S+) (\S+) (.+?(?=\[)|.+?(?=))[^a-zA-Z0-9](\d{1,7}|)[^a-zA-Z0-9]{1,3}PWD=([^ ]+) ; USER=([^ ]+) ; COMMAND=(.*)$') as matches 301 | from 302 | exec_command_line 303 | where 304 | command = 'cat /var/log/auth.log' 305 | order by 306 | _ctx ->> 'connection_name', 307 | line_number 308 | ) 309 | subquery; 310 | 311 | ```sql+sqlite 312 | Error: SQLite does not support regex operations. 313 | ``` 314 | 315 | ### List /etc/login.defs settings on Linux host 316 | Determine the settings of a Linux host's login configuration. This query is useful for system administrators seeking to understand and manage user login preferences on a Linux system. 317 | 318 | ```sql+postgres 319 | select 320 | host, 321 | matches[1] as option, 322 | matches[2] as setting 323 | from 324 | ( 325 | select 326 | _ctx ->> 'connection_name' as host, 327 | regexp_matches(line, '^(\S+)\s+(\S+)') as matches 328 | from 329 | exec_command_line 330 | where 331 | command = 'grep -vE ''^($|#)'' /etc/login.defs' 332 | order by 333 | host, 334 | line_number 335 | ) 336 | subquery; 337 | ``` 338 | 339 | ```sql+sqlite 340 | Error: SQLite does not support regex operations. 341 | ``` 342 | 343 | ### List installed packages on Linux/Debian host 344 | Determine the software packages installed on a Linux/Debian host. This is particularly useful for system administrators needing to manage software installations and updates across multiple systems. 345 | 346 | ```sql+postgres 347 | select 348 | host, 349 | matches[1] as option, 350 | matches[2] as setting 351 | from 352 | ( 353 | select 354 | _ctx ->> 'connection_name' as host, 355 | regexp_matches(line, '^(\\S+)\\h(\\S+)\\h(\\S+)\\h(.*)') as matches 356 | from 357 | exec_command_line 358 | where 359 | command = 'apt list --installed' 360 | order by 361 | host, 362 | line_number 363 | limit 20 364 | ) 365 | subquery; 366 | ``` 367 | 368 | ```sql+sqlite 369 | Error: The corresponding SQLite query is unavailable. 370 | ``` 371 | 372 | ### Query processor through Python interpreter on local machine 373 | Analyze your local machine's processor type by executing a Python command. This can be useful for system diagnostics or when tailoring software to specific hardware. 374 | This example requires Python3 interpreter to be set on `exec.spc` file. Please refer [this](index.md#local-connection-using-a-specific-interpreter) on how to set it up. 375 | 376 | 377 | ```sql+postgres 378 | select 379 | line as processor 380 | from 381 | exec_command_line 382 | where 383 | command = 'import platform; print(platform.processor())'; 384 | ``` 385 | 386 | ```sql+sqlite 387 | select 388 | line as processor 389 | from 390 | exec_command_line 391 | where 392 | command = 'import platform; print(platform.processor())'; 393 | ``` 394 | 395 | ### Query disk usage through Python interpreter on local machine 396 | Analyze the settings to understand the usage of disk space on your local machine through the Python interpreter. This can help you manage your storage effectively by identifying how much space is used and how much is still available. 397 | This example requires Python3 interpreter to be set on `exec.spc` file. Please refer [this](index.md#local-connection-using-a-specific-interpreter) on how to set it up. 398 | 399 | ```sql+postgres 400 | select 401 | total, 402 | used, 403 | free 404 | from 405 | exec_command_line, 406 | json_to_record(line::json) as x(total bigint, used bigint, free bigint) 407 | where 408 | command = 'import json, shutil; du = shutil.disk_usage("/"); print(json.dumps({"total": du[0], "used": du[1], "free": du[2]}))'; 409 | ``` 410 | 411 | ```sql+sqlite 412 | Error: The corresponding SQLite query is unavailable. 413 | ``` 414 | 415 | -------------------------------------------------------------------------------- /exec/connection_config.go: -------------------------------------------------------------------------------- 1 | package exec 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "os" 7 | 8 | "github.com/mitchellh/go-homedir" 9 | communicator "github.com/turbot/go-exec-communicator" 10 | "github.com/turbot/go-exec-communicator/shared" 11 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 12 | ) 13 | 14 | type execConfig struct { 15 | WorkingDir *string `hcl:"working_dir"` 16 | Interpreter []string `hcl:"interpreter,optional"` 17 | 18 | Protocol *string `hcl:"protocol"` 19 | User *string `hcl:"user"` 20 | Password *string `hcl:"password"` 21 | PrivateKey *string `hcl:"private_key"` 22 | Certificate *string `hcl:"certificate"` 23 | Host *string `hcl:"host"` 24 | HostKey *string `hcl:"host_key"` 25 | Port *int `hcl:"port"` 26 | Https *bool `hcl:"https"` 27 | Insecure *bool `hcl:"insecure"` 28 | 29 | BastionUser *string `hcl:"bastion_user"` 30 | BastionPassword *string `hcl:"bastion_password"` 31 | BastionPrivateKey *string `hcl:"bastion_private_key"` 32 | BastionHost *string `hcl:"bastion_host"` 33 | BastionHostKey *string `hcl:"bastion_host_key"` 34 | BastionPort *int `hcl:"bastion_port"` 35 | 36 | ProxyHost *string `hcl:"proxy_host"` 37 | ProxyPort *int `hcl:"proxy_port"` 38 | ProxyUserName *string `hcl:"proxy_user_name"` 39 | ProxyUserPassword *string `hcl:"proxy_user_password"` 40 | } 41 | 42 | func ConfigInstance() interface{} { 43 | return &execConfig{} 44 | } 45 | 46 | // GetConfig :: retrieve and cast connection config from query data 47 | func GetConfig(connection *plugin.Connection) execConfig { 48 | if connection == nil || connection.Config == nil { 49 | return execConfig{} 50 | } 51 | config, _ := connection.Config.(execConfig) 52 | return config 53 | } 54 | 55 | // GetCommunicator :: creates a communicator from config 56 | func GetCommunicator(connection *plugin.Connection) (communicator.Communicator, bool, error) { 57 | conf := GetConfig(connection) 58 | 59 | config := shared.ConnectionInfo{ 60 | Timeout: "10s", 61 | } 62 | 63 | // If no other connection info is provided, assume local connection 64 | localConnection := true 65 | 66 | // Bastion settings 67 | if conf.BastionHost != nil { 68 | config.BastionHost = *conf.BastionHost 69 | localConnection = false 70 | 71 | if conf.BastionUser != nil { 72 | config.BastionUser = *conf.BastionUser 73 | } else { 74 | return nil, localConnection, errors.New("bastion_user is required when using bastion host") 75 | } 76 | if conf.BastionPassword != nil { 77 | config.BastionPassword = *conf.BastionPassword 78 | } else if conf.BastionPrivateKey != nil { 79 | content, err := PathOrContents(*conf.BastionPrivateKey) 80 | if err != nil { 81 | return nil, localConnection, err 82 | } 83 | config.BastionPrivateKey = content 84 | } else { 85 | return nil, localConnection, errors.New("either bastion_password or bastion_private_key is required when using bastion host") 86 | } 87 | } 88 | if conf.BastionHostKey != nil { 89 | config.BastionHostKey = *conf.BastionHostKey 90 | localConnection = false 91 | } 92 | if conf.BastionPort != nil { 93 | config.BastionPort = uint16(*conf.BastionPort) 94 | localConnection = false 95 | } 96 | 97 | // PROXY settings 98 | if conf.ProxyHost != nil { 99 | config.ProxyHost = *conf.ProxyHost 100 | localConnection = false 101 | } 102 | if conf.ProxyPort != nil { 103 | config.ProxyPort = uint16(*conf.ProxyPort) 104 | localConnection = false 105 | } 106 | if conf.ProxyUserName != nil { 107 | config.ProxyUserName = *conf.ProxyUserName 108 | localConnection = false 109 | } 110 | if conf.ProxyUserPassword != nil { 111 | config.ProxyUserPassword = *conf.ProxyUserPassword 112 | localConnection = false 113 | } else { 114 | if conf.ProxyUserName != nil { 115 | return nil, localConnection, errors.New("password is required when proxy username is set") 116 | } 117 | } 118 | 119 | // Detects remote connection 120 | if conf.Protocol != nil || conf.Host != nil || conf.Port != nil || conf.Https != nil || conf.Insecure != nil || conf.User != nil || conf.Password != nil || conf.PrivateKey != nil { 121 | localConnection = false 122 | } 123 | 124 | if conf.Protocol != nil { 125 | config.Type = *conf.Protocol 126 | } else { 127 | if !localConnection { 128 | return nil, localConnection, errors.New("protocol is required in config") 129 | } 130 | } 131 | if conf.Host != nil { 132 | config.Host = *conf.Host 133 | } else { 134 | if !localConnection { 135 | return nil, localConnection, errors.New("host is required in config") 136 | } 137 | } 138 | if conf.Port != nil { 139 | config.Port = uint16(*conf.Port) 140 | } 141 | if conf.Https != nil { 142 | config.HTTPS = *conf.Https 143 | } 144 | if conf.Insecure != nil { 145 | config.Insecure = *conf.Insecure 146 | } 147 | 148 | if config.Type == "ssh" { 149 | if conf.User != nil { 150 | config.User = *conf.User 151 | } else { 152 | return nil, localConnection, errors.New("user is required for SSH connections") 153 | } 154 | if conf.Password != nil { 155 | config.Password = *conf.Password 156 | } else if conf.PrivateKey != nil { 157 | content, err := PathOrContents(*conf.PrivateKey) 158 | if err != nil { 159 | return nil, localConnection, err 160 | } 161 | config.PrivateKey = content 162 | } else { 163 | return nil, localConnection, errors.New("either password or private_key is required for SSH connections") 164 | } 165 | } 166 | if config.Type == "winrm" { 167 | if conf.User != nil { 168 | config.User = *conf.User 169 | } else { 170 | return nil, localConnection, errors.New("user is required for WinRM connections") 171 | } 172 | if conf.Password != nil { 173 | config.Password = *conf.Password 174 | } else { 175 | return nil, localConnection, errors.New("password is required for WinRM connections") 176 | } 177 | } 178 | 179 | if localConnection { 180 | return nil, localConnection, nil 181 | } 182 | 183 | comm, err := communicator.New(config) 184 | return comm, localConnection, err 185 | } 186 | 187 | // PathOrContents :: returns the contents of a file if the parameter is a file path, otherwise returns the parameter itself 188 | func PathOrContents(poc string) (string, error) { 189 | if len(poc) == 0 { 190 | return poc, nil 191 | } 192 | 193 | path := poc 194 | if path[0] == '~' { 195 | var err error 196 | path, err = homedir.Expand(path) 197 | if err != nil { 198 | return path, err 199 | } 200 | } 201 | 202 | // Check for valid file path 203 | if _, err := os.Stat(path); err == nil { 204 | contents, err := os.ReadFile(path) 205 | if err != nil { 206 | return string(contents), err 207 | } 208 | return string(contents), nil 209 | } 210 | 211 | // Return error if content is a file path and the file doesn't exist 212 | if len(path) > 1 && (path[0] == '/' || path[0] == '\\') { 213 | return "", fmt.Errorf("%s: no such file or dir", path) 214 | } 215 | 216 | // Return the inline content 217 | return poc, nil 218 | } 219 | -------------------------------------------------------------------------------- /exec/plugin.go: -------------------------------------------------------------------------------- 1 | package exec 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 7 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" 8 | "github.com/turbot/steampipe-plugin-sdk/v5/rate_limiter" 9 | ) 10 | 11 | func Plugin(ctx context.Context) *plugin.Plugin { 12 | p := &plugin.Plugin{ 13 | Name: "steampipe-plugin-exec", 14 | ConnectionConfigSchema: &plugin.ConnectionConfigSchema{ 15 | NewInstance: ConfigInstance, 16 | }, 17 | RateLimiters: []*rate_limiter.Definition{ 18 | { 19 | MaxConcurrency: 15, 20 | Name: "exec_global", 21 | }, 22 | }, 23 | DefaultTransform: transform.FromGo(), 24 | TableMap: map[string]*plugin.Table{ 25 | "exec_command": tableExecCommand(ctx), 26 | "exec_command_line": tableExecCommandLine(ctx), 27 | }, 28 | } 29 | return p 30 | } 31 | -------------------------------------------------------------------------------- /exec/table_exec_command.go: -------------------------------------------------------------------------------- 1 | package exec 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "io" 7 | "strings" 8 | "sync" 9 | 10 | communicator "github.com/turbot/go-exec-communicator" 11 | "github.com/turbot/go-exec-communicator/remote" 12 | "github.com/turbot/go-exec-communicator/shared" 13 | "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" 14 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 15 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" 16 | ) 17 | 18 | func tableExecCommand(ctx context.Context) *plugin.Table { 19 | return &plugin.Table{ 20 | Name: "exec_command", 21 | Description: "Execute a command locally or on a remote machine and return the output as a single row.", 22 | List: &plugin.ListConfig{ 23 | Hydrate: listExecCommand, 24 | KeyColumns: []*plugin.KeyColumn{ 25 | {Name: "command", Require: plugin.Required}, 26 | }, 27 | }, 28 | Columns: []*plugin.Column{ 29 | // Top columns 30 | {Name: "stdout_output", Type: proto.ColumnType_STRING, Description: "Standard output from the command."}, 31 | {Name: "stderr_output", Type: proto.ColumnType_STRING, Description: "Standard error output from the command."}, 32 | {Name: "exit_code", Type: proto.ColumnType_INT, Description: "Exit code of the command."}, 33 | {Name: "command", Type: proto.ColumnType_STRING, Transform: transform.FromQual("command"), Description: "Command to be run."}, 34 | }, 35 | } 36 | } 37 | 38 | func listExecCommand(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { 39 | comm, isLocalConnection, err := GetCommunicator(d.Connection) 40 | if err != nil { 41 | plugin.Logger(ctx).Error("listExecCommand", "configuration_error", err) 42 | return nil, err 43 | } 44 | if isLocalConnection { 45 | return listLocalCommand(ctx, d, h) 46 | } 47 | 48 | command := d.EqualsQualString("command") 49 | if command == "" { 50 | // Empty command returns zero rows 51 | return nil, nil 52 | } 53 | 54 | var cmd *remote.Cmd 55 | 56 | outR, outW := io.Pipe() 57 | defer outW.Close() 58 | 59 | var wg sync.WaitGroup 60 | 61 | stdout := "" 62 | 63 | wg.Add(1) 64 | go func() { 65 | defer wg.Done() 66 | buf := new(strings.Builder) 67 | _, err := io.Copy(buf, outR) 68 | if err != nil { 69 | plugin.Logger(ctx).Error("listExecCommand", "output_read_error", err) 70 | } 71 | stdout = buf.String() 72 | }() 73 | 74 | retryCtx, cancel := context.WithTimeout(ctx, comm.Timeout()) 75 | defer cancel() 76 | 77 | // Wait and retry until we establish the connection 78 | o := shared.Outputter{} 79 | err = communicator.Retry(retryCtx, func() error { 80 | return comm.Connect(&o) 81 | }) 82 | if err != nil { 83 | plugin.Logger(ctx).Error("listExecCommand", "connection_error", err) 84 | return nil, err 85 | } 86 | 87 | // Wait for the context to end and then disconnect 88 | go func() { 89 | plugin.Logger(ctx).Debug("listExecCommand", "wait for it...") 90 | <-ctx.Done() 91 | plugin.Logger(ctx).Debug("listExecCommand", "done!") 92 | plugin.Logger(ctx).Debug("listExecCommand", "disconnecting...") 93 | err = comm.Disconnect() 94 | if err != nil { 95 | plugin.Logger(ctx).Error("listExecCommand", "disconnection failure") 96 | } 97 | plugin.Logger(ctx).Debug("listExecCommand", "disconnected") 98 | }() 99 | 100 | cmd = &remote.Cmd{ 101 | Command: command, 102 | Stdout: outW, 103 | } 104 | 105 | result := commandResult{} 106 | 107 | plugin.Logger(ctx).Debug("listExecCommand", "cmd.Start...") 108 | if err := comm.Start(cmd); err != nil { 109 | plugin.Logger(ctx).Error("listExecCommand.comm.Start", "command_error", err) 110 | return nil, err 111 | } 112 | plugin.Logger(ctx).Debug("listExecCommand", "cmd.Start done") 113 | 114 | plugin.Logger(ctx).Debug("listExecCommand", "cmd.Wait...") 115 | if err := cmd.Wait(); err != nil { 116 | plugin.Logger(ctx).Error("listExecCommand.cmd.Wait", "command_error", err) 117 | if e, ok := err.(*remote.ExitError); ok { 118 | result.ExitCode = e.ExitStatus 119 | } 120 | } 121 | plugin.Logger(ctx).Debug("listExecCommand", "cmd.Wait done") 122 | 123 | plugin.Logger(ctx).Debug("listExecCommand", "comm.Disconnect...") 124 | outW.Close() 125 | err = comm.Disconnect() 126 | if err != nil { 127 | plugin.Logger(ctx).Error("listExecCommand", "disconnection_failure") 128 | } 129 | plugin.Logger(ctx).Debug("listExecCommand", "comm.Disconnect done") 130 | 131 | plugin.Logger(ctx).Debug("listExecCommand", "wg waiting...") 132 | wg.Wait() 133 | plugin.Logger(ctx).Debug("listExecCommand", "wg done!") 134 | 135 | plugin.Logger(ctx).Debug("listExecCommand", "adding row...") 136 | 137 | // If the command failed, return the stderr output 138 | if result.ExitCode != 0 { 139 | d.StreamListItem(ctx, commandResult{StderrOutput: stdout, ExitCode: result.ExitCode}) 140 | return nil, nil 141 | } 142 | 143 | d.StreamListItem(ctx, commandResult{StdoutOutput: stdout, ExitCode: result.ExitCode}) 144 | return nil, nil 145 | } 146 | 147 | func listLocalCommand(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { 148 | 149 | cmd, err := prepareCommand(ctx, d, h) 150 | if err != nil { 151 | plugin.Logger(ctx).Error("listLocalCommand", "prepareCommand", "command_error", err) 152 | return nil, err 153 | } 154 | 155 | if cmd == nil { 156 | // Empty command returns zero rows 157 | plugin.Logger(ctx).Debug("listLocalCommand", "cmd", cmd) 158 | return nil, err 159 | } 160 | 161 | stdout, err := cmd.StdoutPipe() 162 | if err != nil { 163 | plugin.Logger(ctx).Error("listLocalCommand", "stdout_read_error", err) 164 | return nil, err 165 | } 166 | 167 | stderr, err := cmd.StderrPipe() 168 | if err != nil { 169 | plugin.Logger(ctx).Error("listLocalCommand", "stderr_read_error", err) 170 | return nil, err 171 | } 172 | 173 | if err := cmd.Start(); err != nil { 174 | plugin.Logger(ctx).Error("listLocalCommand", "command_start_error", err) 175 | return nil, err 176 | } 177 | 178 | // Create slices to store standard output and standard error lines 179 | var stdoutBytes bytes.Buffer 180 | var stderrBytes bytes.Buffer 181 | 182 | // Read standard output and standard error concurrently 183 | _, err = io.Copy(&stdoutBytes, stdout) 184 | if err != nil { 185 | plugin.Logger(ctx).Error("listLocalCommand", "stdout_read_error", err) 186 | } 187 | 188 | _, err = io.Copy(&stderrBytes, stderr) 189 | if err != nil { 190 | plugin.Logger(ctx).Error("listLocalCommand", "stderr_read_error", err) 191 | } 192 | 193 | if err := cmd.Wait(); err != nil { 194 | // Log the error, but don't fail. The command error output will be captured and returned to the user. 195 | plugin.Logger(ctx).Error("listLocalCommand", "cmd.Wait", "command_error", err) 196 | } 197 | 198 | result := commandResult{ 199 | StdoutOutput: stdoutBytes.String(), 200 | StderrOutput: stderrBytes.String(), 201 | ExitCode: cmd.ProcessState.ExitCode(), 202 | } 203 | d.StreamListItem(ctx, result) 204 | 205 | return nil, nil 206 | } 207 | -------------------------------------------------------------------------------- /exec/table_exec_command_line.go: -------------------------------------------------------------------------------- 1 | package exec 2 | 3 | import ( 4 | "bufio" 5 | "context" 6 | "io" 7 | "log" 8 | "sync" 9 | 10 | "github.com/mitchellh/go-linereader" 11 | communicator "github.com/turbot/go-exec-communicator" 12 | "github.com/turbot/go-exec-communicator/remote" 13 | "github.com/turbot/go-exec-communicator/shared" 14 | "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" 15 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 16 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" 17 | ) 18 | 19 | func tableExecCommandLine(ctx context.Context) *plugin.Table { 20 | return &plugin.Table{ 21 | Name: "exec_command_line", 22 | Description: "Execute a command locally or on a remote machine and return one row per output line.", 23 | List: &plugin.ListConfig{ 24 | Hydrate: listExecCommandLine, 25 | KeyColumns: []*plugin.KeyColumn{ 26 | {Name: "command", Require: plugin.Required}, 27 | }, 28 | }, 29 | Columns: []*plugin.Column{ 30 | // Top columns 31 | {Name: "line", Type: proto.ColumnType_STRING, Description: "Line data."}, 32 | {Name: "stream", Type: proto.ColumnType_STRING, Description: "Stream the line was sent to, e.g. stdout or stderr."}, 33 | {Name: "line_number", Type: proto.ColumnType_INT, Description: "Line number within the stream."}, 34 | {Name: "command", Type: proto.ColumnType_STRING, Transform: transform.FromQual("command"), Description: "Command to be run."}, 35 | }, 36 | } 37 | } 38 | 39 | func listExecCommandLine(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { 40 | comm, isLocalConnection, err := GetCommunicator(d.Connection) 41 | if err != nil { 42 | plugin.Logger(ctx).Error("listRemoteCommandResult", "init", "command_error", err) 43 | return nil, err 44 | } 45 | if isLocalConnection { 46 | return listLocalCommandLine(ctx, d, h) 47 | } 48 | 49 | command := d.EqualsQualString("command") 50 | if command == "" { 51 | // Empty command returns zero rows 52 | return nil, nil 53 | } 54 | 55 | var cmd *remote.Cmd 56 | 57 | outR, outW := io.Pipe() 58 | defer outW.Close() 59 | 60 | var wg sync.WaitGroup 61 | 62 | output := []string{} 63 | 64 | wg.Add(1) 65 | go func() { 66 | defer wg.Done() 67 | lr := linereader.New(outR) 68 | for line := range lr.Ch { 69 | output = append(output, line) 70 | } 71 | }() 72 | 73 | retryCtx, cancel := context.WithTimeout(ctx, comm.Timeout()) 74 | defer cancel() 75 | 76 | // Wait and retry until we establish the connection 77 | o := shared.Outputter{} 78 | err = communicator.Retry(retryCtx, func() error { 79 | return comm.Connect(&o) 80 | }) 81 | if err != nil { 82 | plugin.Logger(ctx).Error("listRemoteCommandResult", "connection_error", err) 83 | return nil, err 84 | } 85 | 86 | // Wait for the context to end and then disconnect 87 | go func() { 88 | plugin.Logger(ctx).Debug("listRemoteCommandResult", "ctx_done", "wait for it...") 89 | <-ctx.Done() 90 | plugin.Logger(ctx).Debug("listRemoteCommandResult", "ctx_done", "done!") 91 | plugin.Logger(ctx).Debug("listRemoteCommandResult", "ctx_done", "disconnecting...") 92 | err = comm.Disconnect() 93 | if err != nil { 94 | plugin.Logger(ctx).Error("listRemoteCommandResult", "ctx_done", "disconnection failed") 95 | } 96 | plugin.Logger(ctx).Debug("listRemoteCommandResult", "ctx_done", "disconnected") 97 | }() 98 | 99 | cmd = &remote.Cmd{ 100 | Command: command, 101 | Stdout: outW, 102 | } 103 | 104 | result := commandResult{} 105 | 106 | plugin.Logger(ctx).Debug("listRemoteCommandResult", "ctx_done", "cmd.Start...") 107 | if err := comm.Start(cmd); err != nil { 108 | plugin.Logger(ctx).Error("listRemoteCommandResult", "comm.Start", "command_error", err) 109 | return nil, err 110 | } 111 | plugin.Logger(ctx).Debug("listRemoteCommandResult", "ctx_done", "cmd.Start done") 112 | 113 | plugin.Logger(ctx).Debug("listRemoteCommandResult", "ctx_done", "cmd.Wait...") 114 | if err := cmd.Wait(); err != nil { 115 | plugin.Logger(ctx).Error("listRemoteCommandResult", "comm.Wait", "command_error", err) 116 | if e, ok := err.(*remote.ExitError); ok { 117 | result.ExitCode = e.ExitStatus 118 | } 119 | } 120 | plugin.Logger(ctx).Debug("listRemoteCommandResult", "ctx_done", "cmd.Wait done") 121 | 122 | plugin.Logger(ctx).Debug("listRemoteCommandResult", "ctx_done", "comm.Disconnect...") 123 | outW.Close() 124 | err = comm.Disconnect() 125 | if err != nil { 126 | plugin.Logger(ctx).Error("listRemoteCommandResult", "ctx_done", "disconnection failed") 127 | } 128 | plugin.Logger(ctx).Debug("listRemoteCommandResult", "ctx_done", "comm.Disconnect done") 129 | 130 | plugin.Logger(ctx).Debug("listRemoteCommandResult", "ctx_done", "wg waiting...") 131 | wg.Wait() 132 | plugin.Logger(ctx).Debug("listRemoteCommandResult", "ctx_done", "wg done!") 133 | 134 | plugin.Logger(ctx).Debug("listExecCommand", "ctx_done", "adding row...") 135 | 136 | // If the command failed, return the stderr output 137 | if result.ExitCode != 0 { 138 | for i, line := range output { 139 | d.StreamListItem(ctx, outputRow{Line: line, LineNumber: i + 1, Stream: "stderr"}) 140 | } 141 | return nil, nil 142 | } 143 | 144 | for i, line := range output { 145 | d.StreamListItem(ctx, outputRow{Line: line, LineNumber: i + 1, Stream: "stdout"}) 146 | } 147 | return nil, nil 148 | } 149 | 150 | func listLocalCommandLine(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { 151 | 152 | cmd, err := prepareCommand(ctx, d, h) 153 | if err != nil { 154 | plugin.Logger(ctx).Error("listLocalCommandLine", "command_error", err) 155 | return nil, err 156 | } 157 | 158 | if cmd == nil { 159 | // Empty command returns zero rows 160 | return nil, nil 161 | } 162 | 163 | stdout, err := cmd.StdoutPipe() 164 | if err != nil { 165 | plugin.Logger(ctx).Error("listLocalCommandLine", "pipe_error", err) 166 | log.Fatal(err) 167 | } 168 | 169 | stderr, err := cmd.StderrPipe() 170 | if err != nil { 171 | plugin.Logger(ctx).Error("listLocalCommandLine", "pipe_error", err) 172 | return nil, err 173 | } 174 | 175 | if err := cmd.Start(); err != nil { 176 | plugin.Logger(ctx).Error("listLocalCommandLine", "command_error", err) 177 | return nil, err 178 | } 179 | 180 | stdoutScanner := bufio.NewScanner(stdout) 181 | lineNumber := 0 182 | for stdoutScanner.Scan() { 183 | lineNumber++ 184 | d.StreamListItem(ctx, outputRow{LineNumber: lineNumber, Line: stdoutScanner.Text(), Stream: "stdout"}) 185 | } 186 | if err := stdoutScanner.Err(); err != nil { 187 | plugin.Logger(ctx).Error("listLocalCommandLine", "stdout_error", err) 188 | return nil, err 189 | } 190 | 191 | stderrScanner := bufio.NewScanner(stderr) 192 | for stderrScanner.Scan() { 193 | lineNumber++ 194 | d.StreamListItem(ctx, outputRow{LineNumber: lineNumber, Line: stderrScanner.Text(), Stream: "stderr"}) 195 | } 196 | if err := stderrScanner.Err(); err != nil { 197 | plugin.Logger(ctx).Error("listLocalCommandLine", "stderr_error", err) 198 | return nil, err 199 | } 200 | 201 | if err := cmd.Wait(); err != nil { 202 | // Log the error, but don't fail. The command error output will be captured 203 | // and returned to the user. 204 | plugin.Logger(ctx).Error("listLocalCommandLine", "command_error", err) 205 | } 206 | 207 | return nil, nil 208 | } 209 | -------------------------------------------------------------------------------- /exec/utils.go: -------------------------------------------------------------------------------- 1 | package exec 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "os" 7 | "os/exec" 8 | "runtime" 9 | 10 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 11 | ) 12 | 13 | type commandResult struct { 14 | StdoutOutput string `json:"stdout_output"` 15 | StderrOutput string `json:"stderr_output"` 16 | ExitCode int `json:"exit_code"` 17 | } 18 | 19 | type outputRow struct { 20 | LineNumber int 21 | Line string 22 | Stream string 23 | } 24 | 25 | func prepareCommand(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (*exec.Cmd, error) { 26 | 27 | conf := GetConfig(d.Connection) 28 | 29 | plugin.Logger(ctx).Debug("listLocalCommand", "conf", conf) 30 | 31 | command := d.EqualsQualString("command") 32 | if command == "" { 33 | // Empty command returns zero rows 34 | return nil, nil 35 | } 36 | 37 | plugin.Logger(ctx).Debug("listLocalCommand", "command", command) 38 | 39 | envVal := map[string]string{"TODO": "support_map_config"} 40 | var env []string 41 | if len(envVal) > 0 { 42 | for k, v := range envVal { 43 | if v != "" { 44 | entry := fmt.Sprintf("%s=%s", k, v) 45 | env = append(env, entry) 46 | } 47 | } 48 | } 49 | 50 | plugin.Logger(ctx).Debug("listLocalCommand", "env", env) 51 | 52 | // Choose the shell interpreter and add it to the start of the command 53 | var cmdargs []string 54 | if len(conf.Interpreter) > 0 { 55 | for _, v := range conf.Interpreter { 56 | if v != "" { 57 | cmdargs = append(cmdargs, v) 58 | } 59 | } 60 | } else { 61 | if runtime.GOOS == "windows" { 62 | cmdargs = []string{"cmd", "/C"} 63 | } else { 64 | cmdargs = []string{"/bin/sh", "-c"} 65 | } 66 | } 67 | 68 | // Command comes last 69 | cmdargs = append(cmdargs, command) 70 | 71 | plugin.Logger(ctx).Debug("listLocalCommand", "cmdargs", cmdargs) 72 | 73 | cmd := exec.CommandContext(ctx, cmdargs[0], cmdargs[1:]...) 74 | 75 | // Dir specifies the working directory of the command. 76 | // If Dir is the empty string (this is default), runs the command 77 | // in the calling process's current directory. 78 | if conf.WorkingDir != nil { 79 | cmd.Dir = *conf.WorkingDir 80 | } 81 | 82 | // Env specifies the environment of the command. 83 | // By default will use the calling process's environment 84 | var cmdEnv []string 85 | cmdEnv = os.Environ() 86 | cmdEnv = append(cmdEnv, env...) 87 | cmd.Env = cmdEnv 88 | 89 | return cmd, nil 90 | } 91 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/turbot/steampipe-plugin-exec 2 | 3 | go 1.23.1 4 | 5 | toolchain go1.23.2 6 | 7 | require ( 8 | github.com/mitchellh/go-homedir v1.1.0 9 | github.com/mitchellh/go-linereader v0.0.0-20190213213312-1b945b3263eb 10 | github.com/turbot/go-exec-communicator v0.0.0-20230412124734-9374347749b6 11 | github.com/turbot/steampipe-plugin-sdk/v5 v5.11.6 12 | 13 | ) 14 | 15 | require ( 16 | cloud.google.com/go v0.112.1 // indirect 17 | cloud.google.com/go/compute/metadata v0.3.0 // indirect 18 | cloud.google.com/go/iam v1.1.6 // indirect 19 | cloud.google.com/go/storage v1.38.0 // indirect 20 | github.com/Azure/go-ntlmssp v0.0.0-20211209120228-48547f28849e // indirect 21 | github.com/ChrisTrenkamp/goxpath v0.0.0-20210404020558-97928f7e12b6 // indirect 22 | github.com/Microsoft/go-winio v0.5.2 // indirect 23 | github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect 24 | github.com/agext/levenshtein v1.2.3 // indirect 25 | github.com/allegro/bigcache/v3 v3.1.0 // indirect 26 | github.com/apparentlymart/go-shquot v0.0.1 // indirect 27 | github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect 28 | github.com/aws/aws-sdk-go v1.44.183 // indirect 29 | github.com/beorn7/perks v1.0.1 // indirect 30 | github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect 31 | github.com/btubbs/datetime v0.1.1 // indirect 32 | github.com/cenkalti/backoff/v4 v4.3.0 // indirect 33 | github.com/cespare/xxhash/v2 v2.3.0 // indirect 34 | github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect 35 | github.com/dgraph-io/ristretto v0.2.0 // indirect 36 | github.com/dustin/go-humanize v1.0.1 // indirect 37 | github.com/dylanmei/iso8601 v0.1.0 // indirect 38 | github.com/eko/gocache/lib/v4 v4.1.6 // indirect 39 | github.com/eko/gocache/store/bigcache/v4 v4.2.1 // indirect 40 | github.com/eko/gocache/store/ristretto/v4 v4.2.1 // indirect 41 | github.com/fatih/color v1.17.0 // indirect 42 | github.com/felixge/httpsnoop v1.0.4 // indirect 43 | github.com/fsnotify/fsnotify v1.7.0 // indirect 44 | github.com/gertd/go-pluralize v0.2.1 // indirect 45 | github.com/ghodss/yaml v1.0.0 // indirect 46 | github.com/go-logr/logr v1.4.1 // indirect 47 | github.com/go-logr/stdr v1.2.2 // indirect 48 | github.com/gofrs/uuid v4.2.0+incompatible // indirect 49 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect 50 | github.com/golang/mock v1.6.0 // indirect 51 | github.com/golang/protobuf v1.5.4 // indirect 52 | github.com/google/go-cmp v0.6.0 // indirect 53 | github.com/google/s2a-go v0.1.7 // indirect 54 | github.com/google/uuid v1.6.0 // indirect 55 | github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect 56 | github.com/googleapis/gax-go/v2 v2.12.3 // indirect 57 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect 58 | github.com/hashicorp/go-cleanhttp v0.5.2 // indirect 59 | github.com/hashicorp/go-getter v1.7.5 // indirect 60 | github.com/hashicorp/go-hclog v1.6.3 // indirect 61 | github.com/hashicorp/go-plugin v1.6.1 // indirect 62 | github.com/hashicorp/go-safetemp v1.0.0 // indirect 63 | github.com/hashicorp/go-uuid v1.0.3 // indirect 64 | github.com/hashicorp/go-version v1.7.0 // indirect 65 | github.com/hashicorp/hcl/v2 v2.20.1 // indirect 66 | github.com/hashicorp/yamux v0.1.1 // indirect 67 | github.com/iancoleman/strcase v0.3.0 // indirect 68 | github.com/jcmturner/aescts/v2 v2.0.0 // indirect 69 | github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect 70 | github.com/jcmturner/gofork v1.0.0 // indirect 71 | github.com/jcmturner/goidentity/v6 v6.0.1 // indirect 72 | github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect 73 | github.com/jcmturner/rpc/v2 v2.0.3 // indirect 74 | github.com/jmespath/go-jmespath v0.4.0 // indirect 75 | github.com/klauspost/compress v1.17.2 // indirect 76 | github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786 // indirect 77 | github.com/masterzen/winrm v0.0.0-20220917170901-b07f6cb0598d // indirect 78 | github.com/mattn/go-colorable v0.1.13 // indirect 79 | github.com/mattn/go-isatty v0.0.20 // indirect 80 | github.com/mattn/go-runewidth v0.0.15 // indirect 81 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 82 | github.com/mitchellh/go-testing-interface v1.14.1 // indirect 83 | github.com/mitchellh/go-wordwrap v1.0.0 // indirect 84 | github.com/mitchellh/mapstructure v1.5.0 // indirect 85 | github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect 86 | github.com/oklog/run v1.0.0 // indirect 87 | github.com/olekukonko/tablewriter v0.0.5 // indirect 88 | github.com/packer-community/winrmcp v0.0.0-20180921211025-c76d91c1e7db // indirect 89 | github.com/pkg/errors v0.9.1 // indirect 90 | github.com/prometheus/client_golang v1.14.0 // indirect 91 | github.com/prometheus/client_model v0.3.0 // indirect 92 | github.com/prometheus/common v0.37.0 // indirect 93 | github.com/prometheus/procfs v0.8.0 // indirect 94 | github.com/rivo/uniseg v0.2.0 // indirect 95 | github.com/sethvargo/go-retry v0.2.4 // indirect 96 | github.com/stevenle/topsort v0.2.0 // indirect 97 | github.com/tkrajina/go-reflector v0.5.6 // indirect 98 | github.com/turbot/go-kit v1.1.0 // indirect 99 | github.com/ulikunitz/xz v0.5.10 // indirect 100 | github.com/xanzy/ssh-agent v0.3.2 // indirect 101 | github.com/zclconf/go-cty v1.14.4 // indirect 102 | go.opencensus.io v0.24.0 // indirect 103 | go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect 104 | go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect 105 | go.opentelemetry.io/otel v1.26.0 // indirect 106 | go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.26.0 // indirect 107 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect 108 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 // indirect 109 | go.opentelemetry.io/otel/metric v1.26.0 // indirect 110 | go.opentelemetry.io/otel/sdk v1.26.0 // indirect 111 | go.opentelemetry.io/otel/sdk/metric v1.26.0 // indirect 112 | go.opentelemetry.io/otel/trace v1.26.0 // indirect 113 | go.opentelemetry.io/proto/otlp v1.2.0 // indirect 114 | golang.org/x/crypto v0.36.0 // indirect 115 | golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect 116 | golang.org/x/mod v0.19.0 // indirect 117 | golang.org/x/net v0.38.0 // indirect 118 | golang.org/x/oauth2 v0.21.0 // indirect 119 | golang.org/x/sync v0.12.0 // indirect 120 | golang.org/x/sys v0.31.0 // indirect 121 | golang.org/x/text v0.23.0 // indirect 122 | golang.org/x/time v0.5.0 // indirect 123 | golang.org/x/tools v0.23.0 // indirect 124 | google.golang.org/api v0.171.0 // indirect 125 | google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect 126 | google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 // indirect 127 | google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect 128 | google.golang.org/grpc v1.66.0 // indirect 129 | google.golang.org/protobuf v1.34.2 // indirect 130 | gopkg.in/yaml.v2 v2.4.0 // indirect 131 | ) 132 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/turbot/steampipe-plugin-exec/exec" 5 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 6 | ) 7 | 8 | func main() { 9 | plugin.Serve(&plugin.ServeOpts{PluginFunc: exec.Plugin}) 10 | } 11 | --------------------------------------------------------------------------------