3

I want to run a script directly from a windows share. The windows machine is running Windows 7 and I try to run the script from Ubuntu 13.10, on the same LAN. I tried with a bash script as well as a python script and when I run it, I have the following error:

zsh: permission denied: ./bc.sh

The share containg the script is mounted like this:

sudo mount -t cifs -o username=user,passwordpass=,exec,rw,users,file_mode=0777,dir_mode=0777 //192.168.0.3/folder /mnt/Win7

The script has the following rights:

-rwxrwxrwx 0 root root       24 Dec 10 20:50 bc.sh

And contains only a simple command:

#!/bin/bash
echo "Test"

I tried to run it with sudo but didn't work as well.

sudo: unable to execute ./bc.sh: Permission denied

I also tried with bash instead of zsh, without success.

Any idea about what I'm missing?

Thanks.

2 Answers 2

0

you have to execute the script as

       sh path/to/bc.sh
2
  • No, that's not necessary: the script has been made executable, thus it can be run like in the OP Dec 11, 2013 at 11:41
  • If this really is the answer (as marked) then it would be great to understand why. As @MariusMatutiae said, you wouldn't normally need to run it with sh but there's something about the network share that changes this. Nov 7, 2016 at 14:18
0

As far as I know, there are three possible causes why a script might not run when invoked directly.

  1. The execute bit hasn't been set.

    [liveuser@localhost-live ~]$ ls -l ~/*.sh
    -rw-rw-rw-. 1 liveuser liveuser 28 Mar 25 07:55 /home/liveuser/testnox.sh
    -rwxrwxrwx. 1 liveuser liveuser 28 Mar 25 07:23 /home/liveuser/test.sh
    [liveuser@localhost-live ~]$ ~/test.sh
    Hello world.
    [liveuser@localhost-live ~]$ ~/testnox.sh
    bash: /home/liveuser/testnox.sh: Permission denied
    [liveuser@localhost-live ~]$ sh ~/testnox.sh
    Hello world.
    

    Note that you can still run it by invoking sh directly, as long as you've got read access. Also, check if the x bit applies to you. If the file is owned by root and it shows up as -rwx------. then you have to use sudo to run it.

  2. A SELinux rule applies that prevents you from executing the file. I don't know too much about this, but using sudo setenforce 0 beforehand can help in this case. Don't forget to use sudo setenforce 1 when you're done.

    [liveuser@localhost-live ~]$ sestatus
    SELinux status:                 enabled
    SELinuxfs mount:                /sys/fs/selinux
    SELinux root directory:         /etc/selinux
    Loaded policy name:             targeted
    Current mode:                   enforcing
    Mode from config file:          enforcing
    Policy MLS status:              enabled
    Policy deny_unknown status:     allowed
    Max kernel policy version:      30
    [liveuser@localhost-live ~]$ sudo setenforce 0
    [liveuser@localhost-live ~]$ sestatus
    SELinux status:                 enabled
    SELinuxfs mount:                /sys/fs/selinux
    SELinux root directory:         /etc/selinux
    Loaded policy name:             targeted
    Current mode:                   permissive
    Mode from config file:          enforcing
    Policy MLS status:              enabled
    Policy deny_unknown status:     allowed
    Max kernel policy version:      30
    [liveuser@localhost-live ~]$ sudo setenforce 1
    [liveuser@localhost-live ~]$ sestatus
    SELinux status:                 enabled
    SELinuxfs mount:                /sys/fs/selinux
    SELinux root directory:         /etc/selinux
    Loaded policy name:             targeted
    Current mode:                   enforcing
    Mode from config file:          enforcing
    Policy MLS status:              enabled
    Policy deny_unknown status:     allowed
    Max kernel policy version:      30
    
  3. The tree the script resides in was mounted using noexec, which is the default in many cases. Take care that what matters is the (no)exec status of the mount, and that mount --bind sometimes copies neither the status of the parent of the mount point, nor the status of the original volume.

    [liveuser@localhost-live ~]$ ls -l original
    total 4
    -rwxrwxr-x. 1 liveuser liveuser 28 Mar 25 08:14 test.sh
    [liveuser@localhost-live ~]$ ls -l alias
    total 4
    -rwxrwxr-x. 1 liveuser liveuser 28 Mar 25 08:14 test.sh
    [liveuser@localhost-live ~]$ original/test.sh
    Hello world.
    [liveuser@localhost-live ~]$ alias/test.sh
    bash: alias/test.sh: Permission denied
    [liveuser@localhost-live ~]$ sh alias/test.sh
    Hello world.
    [liveuser@localhost-live ~]$ sudo mount -o remount,exec --bind original alias
    [liveuser@localhost-live ~]$ alias/test.sh
    Hello world.
    

One of the reasons Linux can be frustrating is because the error messages don't really give you the detail you need to find a solution. Just Permission denied isn't enough to go on in my opinion. It should say what the actual cause was, for example: Permission denied: /home/liveuser/alias was mounted with noexec. Then you'd know how to go about fixing the problem.

Well, in any case I hope this helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .