2

I have the following prompts

[/share/registrazioni/Script] # cat delete_7gg.sh
#!/bin/sh
find /share/registrazioni/ -type f -mtime +7 -delete
[/share/registrazioni/Script] # which sh
/bin/sh
[/share/registrazioni/Script] # chmod +x delete_7gg.sh
[/share/registrazioni/Script] # ./delete_7gg.sh
-sh: ./delete_7gg.sh: /bin/sh^M: bad interpreter: No such file or directory

why do I get /bin/sh^M: bad interpreter: No such file or directory ? I made the script with vi. I made the script in a qnap qts 4.3.6 that I can reach via ssh. The script should simply delete files older than seven days. I can't install dos2unix because the system has no package manager. I just expected to make a script and put it into cron. but I'm receiving that error instead.

1 Answers1

10

You seem to have Windows-style line endings (CRLF, ^M^J) instead of unix-style line endings (LF, ^J). Try dos2unix

dos2unix delete_7gg.sh

then run as usual

From man:

dos2unix - DOS/MAC to UNIX text file format converter

Siva
  • 9,077
  • thank you for the answer but I made the script in a qnap qts 4.3.6 that I can reach via ssh. It should simply delete files older than seven days. I can't install dos2unix because the system has no package manager. I just expected to make a script and put it into cron. but I'm receiving that error instead. – Malkavian Oct 28 '19 at 14:48
  • @Malkavian Another way: tr -d '\r' < input > output. – Christopher Oct 28 '19 at 14:59