Permission denied when running without bash

2019-08-18 07:44发布

I have a script which calls some other bash, python, and ruby scripts. The script is similar to the following:

#!/bin/bash

set -x

./aux1.py
./aux2.sh

When I run the script from the command line, it runs but it gives me the following output:

./script.sh: line 5: ./aux1.py: Permission denied

The aux.py script has #!/usr/bin/env python at the top; when I call it from the command line with ./aux.py it is fine, however when called from this script in the exact same way I get this error. The strange part is that this only happens when I run the script with ./script.sh; when I run the script with bash script.sh the auxilliary scripts work perfectly.

I'm using Linux, why does this happen?


Update, 3 March 2014

There's nothing conflicting in the PATH, and all of the scripts are chmod +rx. uname -srvmo gives

Linux 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Dec 13 06:58:20 EST 2013 x86_64 GNU/Linux

and there's no more information available in uname -a. SELinux is enabled, but I'm not an administrator so I can't access that information.

标签: linux bash shell
2条回答
家丑人穷心不美
2楼-- · 2019-08-18 07:50

Before launching the main script you must be sure that all the subscripts have got the right permissions. In particular you are interested in the permission for you (your user and owner of the files) to execute the file. This is a short tutorial on permissions. http://blog.pluralsight.com/linux-file-permissions http://www.linux.com/learn/tutorials/309527-understanding-linux-file-permissions

If this is the problem (and it look so), the simpler solution is to run the following commands

chmod u+x script.sh aux1.py aux2.sh

To check whether you have permission to execute simply run

ls -l

You should see something like

-rwxr--r-- 1 youruser youruser 26 Feb 28 21:44 script.sh
-rwxr--r-- 1 youruser youruser 32 Feb 28 21:44 aux1.py

where you should see a "x" in the 4th column corresponding to the file.

查看更多
The star\"
3楼-- · 2019-08-18 07:59

Maybe type sudo su before running your script so that you are the root user. When the script completes simply type exit to get out of root. Type exit again to close the shell.

:D

查看更多
登录 后发表回答