1

I can't execute a script.

I'm struggling with this.

OS version and hardware model

I'm on Raspbian GNU/Linux 10, Raspberry Pi 3 Model B.

Devices

When I call lsblk I get:

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 465.8G  0 disk
└─sda1        8:1    0 465.8G  0 part /mnt/hd
mmcblk0     179:0    0  29.7G  0 disk
├─mmcblk0p1 179:1    0   256M  0 part /boot
└─mmcblk0p2 179:2    0  29.5G  0 part /

File permissions:

When I call ls -la on /mnt/hd I get:

$ ls -la
total 124
drwxr-xr-x  7 user user  4096 May  3 02:52 .
drwxr-xr-x  3 root  root   4096 Mar 29 13:26 ..

...

-rwxr-xr-x  1 user user    49 Apr 30 01:32 start.sh

...

File system information

$ file -sL /dev/sda1
/dev/sda1: Linux rev 1.0 ext4 filesystem data, UUID=dd7c2097-d7cf-4784-bc0f-e8daa9b681ec (extents) (64bit) (large files) (huge files)

Fstab entry:

HDD is mounted on boot with an /etc/fstab entry:

/dev/sda1 /mnt/hd auto defaults,user 0 1

Execution

I do have execution permission, but still when I try to execute start.sh:

$ ./start.sh
-bash: ./start.sh: Permission denied

Script contents

$ cat start.sh
ls

Even though it shows me Permission denied.

What I'm missing here?

  • 1
    using user in fstab implies noexec, so add exec after user ... i.e. /dev/sda1 /mnt/hd auto defaults,user,exec 0 1 – Jaromanda X May 3 at 5:11
  • That solved the issue. Thank you very much. However if you do not want to mount with exec flag you can run: sh start.sh (or your favorite shell interpreter) as the script is just a text file and the interpreter is on another partition (just found it based on your tip). Thanks again for your attention! – user116046 May 3 at 6:16
  • 1
    Please don't solve questions in comments. This will not finish it. @JaromandaX Please make an answer so Edney can accept it. – Ingo May 3 at 8:20
  • 1
    @Edney Please make your solution an answer and accept it after two days. Only accepting an answer will finish the question and it will not pop up again and again for years. – Ingo May 3 at 16:52
  • 1
    @Seamus I know how it works :p – Jaromanda X May 4 at 0:58
0

Thanks to @Jaromanda X.

Using user in fstab implies noexec, so add exec after user:

/dev/sda1 /mnt/hd auto defaults,user,exec 0 1

However if you do not want to mount with exec flag you can run:

$ sh start.sh

(or another script interpreter).

As the script is just a text file and the interpreter is on another partition (exec-able), it will run.

One more note:

Including interpreter she-bang didn't work for me.

| improve this answer | |
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year. – Ingo May 6 at 11:09

Your Answer

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