serviço systemd simples para execução de shell script

serviço systemd simples para execução de shell script

Estou tentando iniciar um arquivo .sh simples e dizFailed at step EXEC spawning /etc/start.sh: No such file or directory

Conteúdo dognome.service

[Unit]
Description=Description for sample script goes here
After=network.target
RequiresMountsFor=/etc/

[Service]
Type=simple
ExecStart=/etc/start.sh
TimeoutStartSec=0

[Install]
WantedBy=default.target

Conteúdo destart.sh

#!/bin/bash
echo "This is a sample script to test auto run during boot" > /root/Documents/script.txt
echo "The time the script run was -->  `date`" >> /root/Documents/script.txt

Saída desystemctl status gnome -l

● gnome.service - Description for sample script goes here
   Loaded: loaded (/etc/systemd/system/gnome.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2019-06-06 18:25:32 CEST; 3s ago
  Process: 11713 ExecStart=/etc/start.sh (code=exited, status=203/EXEC)
 Main PID: 11713 (code=exited, status=203/EXEC)

Jun 06 18:25:32 some.server.adress systemd[1]: Started Description for sample script goes here.
Jun 06 18:25:32 some.server.adress systemd[11713]: Failed at step EXEC spawning /etc/start.sh: No such file or directory
Jun 06 18:25:32 some.server.adress systemd[1]: gnome.service: main process exited, code=exited, status=203/EXEC
Jun 06 18:25:32 some.server.adress systemd[1]: Unit gnome.service entered failed state.
Jun 06 18:25:32 some.server.adress systemd[1]: gnome.service failed.

Saída dels -l /etc/start.sh

-rwxr-xr-x 1 root root 179 Jun  6 18:19 /etc/start.sh

Saída de/etc/start.sh

-bash: /etc/start.sh: /bin/bash^M: bad interpreter: No such file or directory

Responder1

Eu estava usando o Notepad++ no Windows, então tive que executar

sed -i -e 's/\r$//' /etc/start.sh

para substituir os finais de linha do Windows.

O ^M é um caractere de retorno de carro. O Linux usa o caractere de alimentação de linha para marcar o final de uma linha, enquanto o Windows usa a sequência de dois caracteres CR LF. Seu arquivo tem terminações de linha do Windows, o que confunde o Linux.

Tópico de resposta: https://askubuntu.com/questions/304999/not-able-to-execute-a-sh-file-bin-bashm-bad-interpreter

informação relacionada