You are not logged in.
Hello,
I have started to migrate several cron-jobs to systemd-timer.
However there's a failure when executing the systemd-timer that is executing a python script.
This is the original cron-job:
30 1 30 3,6,9,12 * root /opt/susemanager/uyuni-tools/sync_stage.py -p cl-sle12-sp3-sap -e prd -m "$(date +\%d-\%m-\%Y)" 2>&1
Migration this to a systemd service file with this content
[Unit]
Description=Automatic sync stage development cl-sle12-sp3-sap
After=sync_stage_tst_cl-sle12-sp3-sap.service
[Service]
Type=oneshot
ExecStart=/opt/susemanager/uyuni-tools/sync_stage.py -p cl-sle12-sp3-sap -e dev -m "$(date +\%d-\%m-\%Y)"
Environment=HOME=/root
fails when starting the service:
systemctl status sync_stage_dev_cl-sle12-sp3-sap.service
● sync_stage_dev_cl-sle12-sp3-sap.service - Automatic sync stage development cl-sle12-sp3-sap
Loaded: loaded (/etc/systemd/system/sync_stage_dev_cl-sle12-sp3-sap.service; static; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2021-12-13 12:32:08 CET; 5s ago
Process: 1109 ExecStart=/opt/susemanager/uyuni-tools/sync_stage.py -p cl-sle12-sp3-sap -e dev -m $(date +\%d-\e99ccced335a41ea993a71abe276b70d-\%Y) (code=exited, status=2)
Main PID: 1109 (code=exited, status=2)
Dec 13 12:32:08 vlcspsumasrv systemd[1]: Starting Automatic sync stage development cl-sle12-sp3-sap...
Dec 13 12:32:08 vlcspsumasrv sync_stage.py[1109]: usage: sync_stage.py [-h] [-c CHANNEL] [-b] [-p PROJECT] [-e ENVIRONMENT]
Dec 13 12:32:08 vlcspsumasrv sync_stage.py[1109]: [-m MESSAGE] [--version]
Dec 13 12:32:08 vlcspsumasrv sync_stage.py[1109]: sync_stage.py: error: argument -m/--message: expected one argument
Dec 13 12:32:08 vlcspsumasrv systemd[1]: sync_stage_dev_cl-sle12-sp3-sap.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Dec 13 12:32:08 vlcspsumasrv systemd[1]: Failed to start Automatic sync stage development cl-sle12-sp3-sap.
Dec 13 12:32:08 vlcspsumasrv systemd[1]: sync_stage_dev_cl-sle12-sp3-sap.service: Unit entered failed state.
Dec 13 12:32:08 vlcspsumasrv systemd[1]: sync_stage_dev_cl-sle12-sp3-sap.service: Failed with result 'exit-code'.
Can you please advise how to fix this issue?
Removing the \ (backslash) in
-m "$(date +%d-%m-%Y)"
is not solving the problem.
THX
Offline
ExecStart= takes a binary with arguments and does not execute it in a shell, hence "$(date +\%d-\%m-\%Y)" 2>&1 is garbage in this context.
I'd recommend putting the line in a wrapper script in /usr/local/bin.
Last edited by schard (2021-12-13 13:59:38)
Inofficial first vice president of the Rust Evangelism Strike Force
Offline
I tried this
ExecStart=/bin/bash -c '/opt/susemanager/uyuni-tools/sync_stage.py -p cl-sle12-sp3-sap -e dev -m "$(date +\%d-\%m-\%Y)" 2>&1'
but this fails to execute the date-function correctly:
CGroup: /system.slice/sync_stage_dev_cl-sle12-sp3-sap.service
├─13057 /bin/bash -c /opt/susemanager/uyuni-tools/sync_stage.py -p cl-sle12-sp3-sap -e dev -m "$(date +\%d-\e99ccced335a41ea993a71abe276b70d-\%Y)" 2>&1
└─13060 python3 /opt/susemanager/uyuni-tools/sync_stage.py -p cl-sle12-sp3-sap -e dev -m 13-e99ccced335a41ea993a71abe276b70d-2021
Offline
You do not correctly escape the % symbols.
https://www.freedesktop.org/software/sy … Specifiers
tl;dr: It's "%%" not "\%".
Inofficial first vice president of the Rust Evangelism Strike Force
Offline
You do not correctly escape the % symbols.
https://www.freedesktop.org/software/sy … Specifiers
tl;dr: It's "%%" not "\%".
This solution works as expected.
THX
Offline