0

I am trying to do a simple kernel verifying systemd service.

Service is:

[Unit]
Description= It checks kernel version


[Service]
ExecStart=/home/handle-kernel-version.sh $EXPECTED_KERNEL $(uname -r)
StandardOutput=journal+console
EnvironmentFile=/home/input_kernel.txt
Type=oneshot


[Install]
WantedBy=multi-user.target

Problem is, the second argument is passed as $(uname instead of the actual kernel version. I suppose it is due to the systemd handling of escape character and I can surely bypass this issue by adding the uname line in the bash script itself, but I would like to know the solution for the oneline method nevertheless.

EagleOne
  • 541
  • 1
  • 10
  • 28
  • 2
    Does this answer your question? [Adding a shell command inside/inline of a systemd service file](https://stackoverflow.com/questions/48236592/adding-a-shell-command-inside-inline-of-a-systemd-service-file) – Jetchisel Oct 18 '21 at 08:34
  • No, because the OP has no issues with the parameter handling that I'm having so the two questions are not the same – EagleOne Oct 18 '21 at 08:40
  • It is the same, invoke a shell to run shell commands inside a unit file. Is that correct or not? – Jetchisel Oct 18 '21 at 08:41
  • I know how to invoke a shell command, I don't know how to handle the issue at hand. The questions and the related answer do not help me in any useful way. – EagleOne Oct 18 '21 at 08:46
  • 1
    Did you at least tried using the accepted answer and see if it able to solve your issue? – Jetchisel Oct 18 '21 at 08:50
  • 1
    The OP in the in the link is asking for the value of `nproc --all` and the accepted answer used Command Substitution `"$(nproc --all)"` and you're asking how to expand `"$(uname -r)"` .... – Jetchisel Oct 18 '21 at 08:57
  • 1
    @EagleOne: why does the question linked by Jetchisel not help you? You want the same thing. `$(uname -r)` needs to be interpreted by a shell, thus you could use `ExecStart=/bin/bash -c '/home/handle-kernel-version.sh "$EXPECTED_KERNEL" "$(uname -r)"'` to achieve what you want. The only thing I'm wondering about: where does `$EXPECTED_KERNEL` come from? – Fonic Oct 18 '21 at 09:16
  • @Maxxim, it is probably defined by the value of `EnvironmentFile` – Jetchisel Oct 18 '21 at 09:22
  • 1
    @Jetchisel: right, I missed that line. – Fonic Oct 18 '21 at 09:25

0 Answers0