-1

Im trying to start a simple .sh file and it says Failed at step EXEC spawning /etc/start.sh: No such file or directory

Content of the 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

Content of 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

Output of 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.

Output of ls -l /etc/start.sh

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

Output of /etc/start.sh

-bash: /etc/start.sh: /bin/bash^M: bad interpreter: No such file or directory
  • 1
    No such file or directory: Is the script stored in /etc and does it have the executable bit set? Can you post output of ls -l /etc/start.sh (edit your answer to include that information.) Can you run that script on the command line? Do you have something like SELinux that could be interfering with running that script? If that's the case, then try to store it at a more standard location, such as /usr/local/bin and see if that works? – filbranden Jun 6 at 16:44
  • I just created the service by copy-pasting your text and it works flawlessly. Can you run the script in shell? Just try the /etc/start.sh – deimos Jun 14 at 11:55
0

I was using Notepad++ on Windows so I had to run

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

to replace the Windows line endings.

The ^M is a carriage return character. Linux uses the line feed character to mark the end of a line, whereas Windows uses the two-character sequence CR LF. Your file has Windows line endings, which is confusing Linux.

Answer-Thread: https://askubuntu.com/questions/304999/not-able-to-execute-a-sh-file-bin-bashm-bad-interpreter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.