[GH-ISSUE #1702] Bash scripts strange output on Linux agents #1065

Closed
opened 2026-03-02 02:20:55 +03:00 by kerem · 4 comments
Owner

Originally created by @SpookOz on GitHub (Dec 11, 2023).
Original GitHub issue: https://github.com/amidaware/tacticalrmm/issues/1702

Server Info (please complete the following information):

  • OS: Debian 11.8
  • Browser: chrome
  • RMM Version: v0.17.2

Installation Method:

  • Standard

Agent Info (please complete the following information):

  • Agent version: Agent v2.6.0
  • Agent OS: Rocky 8.8 and Debian 11.7 (tested on both)

Describe the bug
It seems the (I believe) since a recent update, some of the Linux scripts are not acting as they should. The scripts are giving unexpected errors r output that do not occur if you run the same script locally. This does not happen with all scripts, just a couple. I have isolated some commands that don't work, but I can't find a pattern.

These examples are specific, but I believe they might point to a common problem in how the scripts are being interpreted in the agent.

To Reproduce

  1. Create a shell script in the Script Manager. Add one of these 2 commands:
    runuser -u apache -- wp plugin status "cloudflare" --path='/var/www/html'
    or
    docker inspect --format='{{if eq .HostConfig.RestartPolicy.Name "unless-stopped"}}{{.Name}}{{end}}' $(docker ps -aq) | grep -v '^$' | sed 's#^/##'

1A. Output if wp plugin status command is run locally:
wp-plugin-status-command-local-output

1B. Output if wp plugin status command is run through TRMM script:
wp-plugin-status-command-RMM-output

2A: Output if docker inspect command is run locally:
docker-inspect-command-local-output

2B: Output if docker inspect command is run through TRMM script:
docker-inspect-command-RMM-output

Expected behavior
Command 1 should output the status of the WordPress plugin. Instead it gives an error
Command 2 should show a list of only the names Docker containers with autostart set. Instead it lists every detail of the containers (as if the --format part of the command is being ignored.

Screenshots
Attached the output if run locally on the client as opposed to through a TRMM script.

Additional context
I'm fairly sure this used to work OK. Note, I have also created bash scripts with the commands in them and run them locally and they work fine. It's just if I run the script through TRMM that the issue occurs.

Originally created by @SpookOz on GitHub (Dec 11, 2023). Original GitHub issue: https://github.com/amidaware/tacticalrmm/issues/1702 **Server Info (please complete the following information):** - OS: Debian 11.8 - Browser: chrome - RMM Version: v0.17.2 **Installation Method:** - Standard **Agent Info (please complete the following information):** - Agent version: Agent v2.6.0 - Agent OS: Rocky 8.8 and Debian 11.7 (tested on both) **Describe the bug** It seems the (I believe) since a recent update, some of the Linux scripts are not acting as they should. The scripts are giving unexpected errors r output that do not occur if you run the same script locally. This does not happen with all scripts, just a couple. I have isolated some commands that don't work, but I can't find a pattern. These examples are specific, but I believe they might point to a common problem in how the scripts are being interpreted in the agent. **To Reproduce** 1. Create a shell script in the Script Manager. Add one of these 2 commands: `runuser -u apache -- wp plugin status "cloudflare" --path='/var/www/html'` or `docker inspect --format='{{if eq .HostConfig.RestartPolicy.Name "unless-stopped"}}{{.Name}}{{end}}' $(docker ps -aq) | grep -v '^$' | sed 's#^/##'` 1A. Output if wp plugin status command is run locally: ![wp-plugin-status-command-local-output](https://github.com/amidaware/tacticalrmm/assets/50608124/ccedba39-47fc-454f-a5f0-720c440d3d2a) 1B. Output if wp plugin status command is run through TRMM script: ![wp-plugin-status-command-RMM-output](https://github.com/amidaware/tacticalrmm/assets/50608124/65618267-b52f-4593-b4bd-de1caa8ed4af) 2A: Output if docker inspect command is run locally: ![docker-inspect-command-local-output](https://github.com/amidaware/tacticalrmm/assets/50608124/6adfb52d-4a28-4482-afab-9a11507a7d8f) 2B: Output if docker inspect command is run through TRMM script: ![docker-inspect-command-RMM-output](https://github.com/amidaware/tacticalrmm/assets/50608124/19625be3-5f0f-42d8-a1d5-5b39cc266134) **Expected behavior** Command 1 should output the status of the WordPress plugin. Instead it gives an error Command 2 should show a list of only the names Docker containers with autostart set. Instead it lists every detail of the containers (as if the --format part of the command is being ignored. **Screenshots** Attached the output if run locally on the client as opposed to through a TRMM script. **Additional context** I'm fairly sure this used to work OK. Note, I have also created bash scripts with the commands in them and run them locally and they work fine. It's just if I run the script through TRMM that the issue occurs.
kerem closed this issue 2026-03-02 02:20:55 +03:00
Author
Owner

@SoarinFerret commented on GitHub (May 28, 2024):

I am running into this too - its from the docker inspect command. The {{...}}} is getting registered as a variable for TacticalRMM, and gets substituted to nothing before being executed. Hence why the entire docker inspect command is getting printed.

An example proving it does not work correctly:

#!/usr/bin/env bash
docker ps --format '{{.ID}} {{.Names}} {{.Status}}'

The only workaround I have found is to use variable expansion to get around the curly braces showing up. For example:

#!/usr/bin/env bash
cb="{{"
docker ps --format "$cb .ID }} $cb .Names }} $cb .Status }}"

Yes, it looks terrible. But it works. I am too tired to try and find a better solution right now, so that's what I am going with - I'll reference this issue number in my script to remember why I did something so silly, and hopefully someone else will come up with something better by the next time I look at it.

<!-- gh-comment-id:2134435858 --> @SoarinFerret commented on GitHub (May 28, 2024): I am running into this too - its from the docker inspect command. The `{{...}}}` is getting registered as a variable for TacticalRMM, and gets substituted to nothing before being executed. Hence why the entire `docker inspect` command is getting printed. An example proving it does not work correctly: ```bash #!/usr/bin/env bash docker ps --format '{{.ID}} {{.Names}} {{.Status}}' ``` The only workaround I have found is to use variable expansion to get around the curly braces showing up. For example: ```bash #!/usr/bin/env bash cb="{{" docker ps --format "$cb .ID }} $cb .Names }} $cb .Status }}" ``` Yes, it looks terrible. But it works. I am too tired to try and find a better solution right now, so that's what I am going with - I'll reference this issue number in my script to remember why I did something so silly, and hopefully someone else will come up with something better by the next time I look at it.
Author
Owner

@SpookOz commented on GitHub (May 29, 2024):

Of course! It's the double brackets! How did I not see that being the issue? Your solution - while not elegant - works well, and I would never have thought of it. Thanks so much!

<!-- gh-comment-id:2136573707 --> @SpookOz commented on GitHub (May 29, 2024): Of course! It's the double brackets! How did I not see that being the issue? Your solution - while not elegant - works well, and I would never have thought of it. Thanks so much!
Author
Owner

@SpookOz commented on GitHub (May 29, 2024):

I think what threw me off is in some instances, it seems to work. for example:

docker ps -a --format "table {{.Names}}\t{{.Status}}\t{{.Image}}"

But I'm not sure why...

Edit: It looks like it is the "\t"

<!-- gh-comment-id:2136582849 --> @SpookOz commented on GitHub (May 29, 2024): I think what threw me off is in some instances, it seems to work. for example: `docker ps -a --format "table {{.Names}}\t{{.Status}}\t{{.Image}}"` But I'm not sure why... Edit: It looks like it is the "\t"
Author
Owner

@wh1te909 commented on GitHub (May 29, 2024):

just pushed a fix for this. will be in next release or if you want to test it out now, run this

wget -O /rmm/api/tacticalrmm/scripts/models.py 'https://raw.githubusercontent.com/amidaware/tacticalrmm/develop/api/tacticalrmm/scripts/models.py' && sudo systemctl restart rmm celery celerybeat
<!-- gh-comment-id:2136641535 --> @wh1te909 commented on GitHub (May 29, 2024): just pushed a fix for this. will be in next release or if you want to test it out now, run this ```bash wget -O /rmm/api/tacticalrmm/scripts/models.py 'https://raw.githubusercontent.com/amidaware/tacticalrmm/develop/api/tacticalrmm/scripts/models.py' && sudo systemctl restart rmm celery celerybeat ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tacticalrmm#1065
No description provided.