単純な.shファイルを実行しようとしていますが、次のように表示されます。Failed at step EXEC spawning /etc/start.sh: No such file or directory
コンテンツgnome.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
コンテンツstart.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
出力systemctl 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.
出力ls -l /etc/start.sh
-rwxr-xr-x 1 root root 179 Jun 6 18:19 /etc/start.sh
出力/etc/start.sh
-bash: /etc/start.sh: /bin/bash^M: bad interpreter: No such file or directory
ベストアンサー1
Windows で Notepad++ を使用しているので、次を実行する必要があります。
sed -i -e 's/\r$//' /etc/start.sh
Windows行の末尾を置き換えます。
^Mはキャリッジリターン文字です。 Linuxは行末を表示するために改行文字を使用し、Windowsは2文字シーケンスCR LFを使用します。ファイルにWindows行末があり、Linuxに混乱を与えます。
答えのトピック: https://askubuntu.com/questions/304999/not-able-to-execute-a-sh-file-bin-bashm-bad-interpreter