When starting a service on Linux, the file exists but the error No such file or directory is displayed

I edited the startup file in Windows and uploaded it to the Linux server. The file was in the directory, but when I started the file, it said "No such file or directory". I checked the contents of the startup file repeatedly and found nothing wrong. It turned out that the problem was with the carriage return character.

Edit the startup file under Windows and upload it toAfter the server was installed, the file was clearly in the directory, but when I started the file, it prompted No such file or directory. I checked the contents of the startup file repeatedly and there was nothing wrong! It turned out that the problem wassuperior.
Enter the following command line:

cat /etc/init.d/v2ray

You will notice that there is a ^M symbol after each line, these are carriage return characters.
The Linux system may not be able to read the shell script correctly when it encounters a script edited under Windows. This may happen when a text editor or terminal creates a file under Windows because Windows uses the carriage return character +as a newline character, while Linux systems use only newline characters.
Remove the carriage returns from your init script. This can be done with a one-line sed:

sed -i -e 's/\r//g' /etc/init.d/v2ray

After deleting the carriage return character, you can successfully start the service.

score

Leave a Reply

Your email address will not be published. Required fields are marked *