3

I have a script called autoinstall:

#!/usr/bin/sh
echo "Installasi membutuhkan free space minimal 2MB, pastikan ada punya cukup space di router anda"
read -p "Anda yakin ingin melanjutkan installasi?(y/n) " -n 1 -r
echo ""
if [[ $REPLY = ^[Yy]$ ]]
then
    cd /
    cd /tmp/
    tar -xvf OpenWrt_Angel_Beats_Edition_v1.3.3.tar -C /
    chmod -R 744 /root/crt
    chmod 744 /www/wget/wget_download.sh
    chmod 744 /usr/bin/gsm
    chmod 744 /usr/bin/profile
    opkg update && opkg install elinks
    cp /etc/rc.local /etc/rc.local.backup
    cat > /etc/rc.local << END
    #!bin/sh
    # /etc/rc.local: Local system initialization script.
    #
    # Put any local startup commands in here. Also, if you have
    # anything that needs to be run at shutdown time you can
    # make an /etc/rc.d/rc.local_shutdown script and put those
    # commands in there.
    sh /www/wget/wget_download.sh > /dev/null 2>&1 &
    exit 0
END
    killall sh /www/wget/wget_download.sh
    sh /www/wget/wget_download.sh > /dev/null 2>&1 &
    echo "File backup /etc/rc.local.backup telah dibuat, gunakan file ini untuk mengembalikan konfigurasi rc.local anda yang dulu jika diperlukan"
    echo "Installasi selesai. Jangan lupa di akun openvpn yang digunakan (/root/crt/xxx.ovpn) tambahkan baris ini:
    script-security 2
    up client-connect.sh"
else
    echo ""
    echo "Installasi dibatalkan"
fi

Every command that I put in the first line always gets the error above (line 1:xxx not found) and I'm sure I've typed in the correct command, even echo gives the error like that, how do I solve this?

Don
  • 235
  • 2
  • 4
  • 16
  • Have you run `/usr/bin/sh` for test? – Hunter Zhao Jan 19 '15 at 13:19
  • yes, but that's not the case, every command that I put in the first line gets error like that, I don't know what went wrong – Don Jan 19 '15 at 13:21
  • What are you using to edit the scripts? A Windows machine? Could this be a `BOM` issue? What does `file – Etan Reisner Jan 19 '15 at 13:22
  • I'm using notepad++ on windows 7 and I run that on my router with OpenWrt installed in it. What do you mean by `file – Don Jan 19 '15 at 13:24

2 Answers2

6

There can be two problems here:

  1. The file doesn't exist. Usually, for sh, the path is /bin/sh, so it should be #!/bin/sh

  2. You're editing the file on Windows. Windows uses CR+LF as line ending. Unix (and Linux) uses just LF. So for Linux, the command reads "execute /bin/sh<CR> and sh<CR> doesn't exist.

Solution: When editing the file, make sure you use Unix line endings.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
1

The file might have been edited with an editor that insert a Unicode BOM (Byte Order Mark).

Have a look to the first line contents with:

od -c autoinstall | head -1

or

hd -n 16 autoinstall

If you see unexpected characters before #!/usr/bin/sh, you might try one of the methods described here Using awk to remove the Byte-order mark to remove the BOM.

Community
  • 1
  • 1
jlliagre
  • 29,783
  • 6
  • 61
  • 72