Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExternalCommand - unable to use dolar sign '$' in arguments to the external command #621

Closed
pawelwod opened this issue Feb 9, 2025 · 1 comment

Comments

@pawelwod
Copy link

pawelwod commented Feb 9, 2025

Adding this kind of ExternalCommand

...
[check.ExternalCommand]
enabled = true
command = test $(date +%H) -gt 7
...

Will result in

...
Feb 09 16:39:41 rzutnik autosuspend[424770]: 2025-02-09 16:39:41,891 - autosuspend - INFO - Configuring check Load with class Load from module autosuspend.checks.activity using config parameters {'enabled': 'true', 'threshold': '10'}
Feb 09 16:39:44 rzutnik autosuspend[424770]: Traceback (most recent call last):
Feb 09 16:39:44 rzutnik autosuspend[424770]:   File "/usr/bin/autosuspend", line 33, in <module>
Feb 09 16:39:44 rzutnik autosuspend[424770]:     sys.exit(load_entry_point('autosuspend==6.0.0', 'console_scripts', 'autosuspend')())
Feb 09 16:39:44 rzutnik autosuspend[424770]:              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 09 16:39:44 rzutnik autosuspend[424770]:   File "/usr/lib/python3/dist-packages/autosuspend/__init__.py", line 793, in main
Feb 09 16:39:44 rzutnik autosuspend[424770]:     args.func(args, config)
Feb 09 16:39:44 rzutnik autosuspend[424770]:   File "/usr/lib/python3/dist-packages/autosuspend/__init__.py", line 760, in main_daemon
Feb 09 16:39:44 rzutnik autosuspend[424770]:     checks = set_up_checks(
Feb 09 16:39:44 rzutnik autosuspend[424770]:              ^^^^^^^^^^^^^^
Feb 09 16:39:44 rzutnik autosuspend[424770]:   File "/usr/lib/python3/dist-packages/autosuspend/__init__.py", line 481, in set_up_checks
Feb 09 16:39:44 rzutnik autosuspend[424770]:     _set_up_single_check(section, prefix, internal_module, target_class)
Feb 09 16:39:44 rzutnik autosuspend[424770]:   File "/usr/lib/python3/dist-packages/autosuspend/__init__.py", line 425, in _set_up_single_check
Feb 09 16:39:44 rzutnik autosuspend[424770]:     config_section_string(section),
Feb 09 16:39:44 rzutnik autosuspend[424770]:     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 09 16:39:44 rzutnik autosuspend[424770]:   File "/usr/lib/python3/dist-packages/autosuspend/__init__.py", line 380, in config_section_string
Feb 09 16:39:44 rzutnik autosuspend[424770]:     data = {k: v if k != "password" else "<redacted>" for k, v in section.items()}
Feb 09 16:39:44 rzutnik autosuspend[424770]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 09 16:39:44 rzutnik autosuspend[424770]:   File "<frozen _collections_abc>", line 894, in __iter__
Feb 09 16:39:44 rzutnik autosuspend[424770]:   File "/usr/lib/python3.12/configparser.py", line 1225, in __getitem__
Feb 09 16:39:44 rzutnik autosuspend[424770]:     return self._parser.get(self._name, key)
Feb 09 16:39:44 rzutnik autosuspend[424770]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 09 16:39:44 rzutnik autosuspend[424770]:   File "/usr/lib/python3.12/configparser.py", line 777, in get
Feb 09 16:39:44 rzutnik autosuspend[424770]:     return self._interpolation.before_get(self, section, option, value,
Feb 09 16:39:44 rzutnik autosuspend[424770]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 09 16:39:44 rzutnik autosuspend[424770]:   File "/usr/lib/python3.12/configparser.py", line 428, in before_get
Feb 09 16:39:44 rzutnik autosuspend[424770]:     self._interpolate_some(parser, option, L, value, section, defaults, 1)
Feb 09 16:39:44 rzutnik autosuspend[424770]:   File "/usr/lib/python3.12/configparser.py", line 488, in _interpolate_some
Feb 09 16:39:44 rzutnik autosuspend[424770]:     raise InterpolationSyntaxError(
Feb 09 16:39:44 rzutnik autosuspend[424770]: configparser.InterpolationSyntaxError: '$' must be followed by '$' or '{', found: '$(date +%H) -gt 7'
Feb 09 16:39:45 rzutnik systemd[1]: autosuspend.service: Main process exited, code=exited, status=1/FAILURE
Feb 09 16:39:45 rzutnik systemd[1]: autosuspend.service: Failed with result 'exit-code'.
Feb 09 16:39:45 rzutnik systemd[1]: autosuspend.service: Consumed 3.665s CPU time.
...

Looks like the configuration values might not be escaped properly.

@languitar
Copy link
Owner

The Dollar sign has a special meaning to the configuration mechanism (interpolation). Try to use two dollar signs to escape the special meaning.

Repository owner locked and limited conversation to collaborators Feb 23, 2025
@languitar languitar converted this issue into discussion #630 Feb 23, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants