|
3 | 3 | Tactical RMM supports uploading existing scripts or creating new scripts from within the web interface.
|
4 | 4 |
|
5 | 5 | Windows agent languages supported:
|
| 6 | + |
6 | 7 | - PowerShell
|
7 | 8 | - Windows Batch
|
8 | 9 | - Python
|
| 10 | +- [Nushell](https://www.nushell.sh/) |
| 11 | +- [Deno](https://deno.com/) |
9 | 12 |
|
10 | 13 | There is [RunAsUser](../howitallworks.md#runasuser-functionality) functionality for Windows.
|
11 | 14 |
|
12 | 15 | Linux/Mac languages supported:
|
| 16 | + |
13 | 17 | - Any language that is installed on the remote machine (use a shebang at the top of the script to set the interpreter)
|
| 18 | +- nu |
| 19 | +- deno (Javascript and TypeScript) |
14 | 20 |
|
15 | 21 | ## Writing Your Own Scripts
|
16 | 22 |
|
@@ -60,6 +66,8 @@ In the dashboard, browse to **Settings > Scripts Manager**. Click the **New** bu
|
60 | 66 | - Windows Batch
|
61 | 67 | - Python
|
62 | 68 | - Shell (use for Linux/macOS scripts)
|
| 69 | + - Nushell |
| 70 | + - Deno |
63 | 71 |
|
64 | 72 | - **Script Arguments** - Optional way to set default arguments for scripts. These will auto populate when running scripts and can be changed at runtime. Logged on Windows Event Viewer > Applications and Services Logs > Microsoft > Windows> PowerShell > Operational
|
65 | 73 | - **Environment vars** - Optional way to set default arguments for scripts using Environment Variables. These will auto populate when running scripts and can be changed at runtime. Not logged, better to use when passing data you don't want logged
|
@@ -169,26 +177,6 @@ Tactical RMM supports getting values from the global key store using the {{globa
|
169 | 177 |
|
170 | 178 | See [Global Keystore](keystore.md).
|
171 | 179 |
|
172 |
| -### Example PowerShell Script |
173 |
| - |
174 |
| -The below script takes five named values. The arguments will look like this: `-SiteName {{site.name}} -ClientName {{client.name}} -PublicIP {{agent.public_ip}} -CustomField {{client.AV_KEY}} -Global {{global.API_KEY}}` |
175 |
| - |
176 |
| -```powershell |
177 |
| -param ( |
178 |
| - [string] $SiteName, |
179 |
| - [string] $ClientName, |
180 |
| - [string] $PublicIp, |
181 |
| - [string] $CustomField, |
182 |
| - [string] $Global |
183 |
| -) |
184 |
| -
|
185 |
| -Write-Output "Site: $SiteName" |
186 |
| -Write-Output "Client: $ClientName" |
187 |
| -Write-Output "Public IP: $PublicIp" |
188 |
| -Write-Output "Custom Fields: $CustomField" |
189 |
| -Write-Output "Global: $Global" |
190 |
| -``` |
191 |
| - |
192 | 180 | ## Script Snippets
|
193 | 181 |
|
194 | 182 | Script Snippets allow you to create common code blocks or comments and apply them to all of your scripts. This could be initialization code, common error checking, or even code comments.
|
@@ -346,3 +334,112 @@ SyntaxError: invalid syntax
|
346 | 334 | ```
|
347 | 335 |
|
348 | 336 | [Python 3.10 introduced the "match" term]: https://docs.python.org/3/whatsnew/3.10.html#pep-634-structural-pattern-matching
|
| 337 | + |
| 338 | +## Nushell |
| 339 | + |
| 340 | +Nu is a new type of shell. Like PowerShell, Nu passes objects from one command to the next. For example, this script will list processes that are more than 100MB. |
| 341 | + |
| 342 | +```nu |
| 343 | +ps | where mem >= 100MB |
| 344 | +``` |
| 345 | + |
| 346 | +There are some important points to keep in mind when writing Nu scripts. See the [Thinking in Nu](https://www.nushell.sh/book/thinking_in_nu.html) for details. Some highlights: |
| 347 | + |
| 348 | +1. The `>` is the greater-than operator, not redirection. Use `| save some-file.txt` |
| 349 | +2. Variables are immutable, or constant. Use [`mut`](https://www.nushell.sh/commands/docs/mut.html#frontmatter-title-for-core) to make a variable mutable. |
| 350 | +3. Currently Nu does not support background tasks. `long-running-command &` will not work. |
| 351 | + |
| 352 | +Nu has a [Discord](https://discord.gg/NtAbbGn) server if you have questions. |
| 353 | + |
| 354 | +To disable this feature, add the following to `local_settings.py`: |
| 355 | + |
| 356 | +```python |
| 357 | +INSTALL_NUSHELL = False |
| 358 | +``` |
| 359 | + |
| 360 | +### Example Nushell Script |
| 361 | + |
| 362 | +The below script find processes sorted by greatest cpu utilization. |
| 363 | + |
| 364 | +```nu |
| 365 | +ps | sort-by cpu | reverse |
| 366 | +``` |
| 367 | + |
| 368 | +## Deno |
| 369 | + |
| 370 | +Deno is considered to be the next iteration of Node.js. Deno uses ECMAScript modules (a.k.a ES Modules or ESM) syntax, not CommonJS (CJS). I.e. use `import * from https://example.com/package/module.ts` instead of `require('./local/file.js')`. |
| 371 | + |
| 372 | +Tactical RMM runs Deno scripts with the following permissions: |
| 373 | + |
| 374 | +``` |
| 375 | +DENO_PERMISSIONS=--allow-all |
| 376 | +``` |
| 377 | + |
| 378 | +See the [documentation on permissions](https://docs.deno.com/runtime/manual/basics/permissions) for details. |
| 379 | + |
| 380 | +To override this, either: |
| 381 | + |
| 382 | +1. Add the `DENO_DEFAULT_PERMISSIONS` [string variable](https://github.com/amidaware/tacticalrmm/blob/1a325a66b45be4c2b8fb2098abb20ef348848651/api/tacticalrmm/tacticalrmm/settings.py#L81) with the permissions requested to `local_settings.py` |
| 383 | +or |
| 384 | +2. Set the `DENO_PERMISSIONS` environment variable to the permissions requested in your script. |
| 385 | + |
| 386 | +To disable this feature, add the following to `local_settings.py`: |
| 387 | + |
| 388 | +```python |
| 389 | +INSTALL_DENO = False |
| 390 | +``` |
| 391 | + |
| 392 | +### Example Deno Script |
| 393 | + |
| 394 | +The below script prints basic system information: |
| 395 | + |
| 396 | +```typescript |
| 397 | +async function gatherSystemInfo() { |
| 398 | + const os = Deno.build.os; |
| 399 | + const arch = Deno.build.arch; |
| 400 | + const memory = Deno.systemMemoryInfo(); |
| 401 | + |
| 402 | + |
| 403 | + const info = ` |
| 404 | +OS: ${os} |
| 405 | +Architecture: ${arch} |
| 406 | +Total Memory: ${(await memory).total / 1024 / 1024} MB |
| 407 | +Free Memory: ${(await memory).free / 1024 / 1024} MB |
| 408 | +`; |
| 409 | + |
| 410 | + console.log(info); |
| 411 | +} |
| 412 | + |
| 413 | +gatherSystemInfo().catch(console.error); |
| 414 | +``` |
| 415 | + |
| 416 | +## Example Scripts |
| 417 | + |
| 418 | +### Example PowerShell Script |
| 419 | + |
| 420 | +The below script takes five named values. The arguments will look like this: `-SiteName {{site.name}}` `-ClientName {{client.name}}` `-PublicIP {{agent.public_ip}}` `-CustomField {{client.AV_KEY}}` `-Global {{global.API_KEY}}` |
| 421 | + |
| 422 | +```powershell |
| 423 | +param ( |
| 424 | + [string] $SiteName, |
| 425 | + [string] $ClientName, |
| 426 | + [string] $PublicIp, |
| 427 | + [string] $CustomField, |
| 428 | + [string] $Global |
| 429 | +) |
| 430 | +
|
| 431 | +Write-Output "Site: $SiteName" |
| 432 | +Write-Output "Client: $ClientName" |
| 433 | +Write-Output "Public IP: $PublicIp" |
| 434 | +Write-Output "Custom Fields: $CustomField" |
| 435 | +Write-Output "Global: $Global" |
| 436 | +``` |
| 437 | + |
| 438 | +### Example Shell Script |
| 439 | + |
| 440 | +The below script prints the user running the script. |
| 441 | + |
| 442 | +```typescript |
| 443 | +#!/usr/bin/env bash |
| 444 | +whoami |
| 445 | +``` |
0 commit comments