Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am running a script but there is an unusual warning: This is what happened in my console

#whoami
root
#ls -l test.sh
-rwxr-xr-x. 1 root root 1894 Feb  2 01:58 test.sh*
#./test.sh
-bash: ./test.sh: Permission denied

Edit: my script:

#!/bin/bash
while read pass port user ip file; do
  echo "startt------------------------------------" $ip
  ping $ip -c 4
  if [ $? -eq 0 ]; then
    echo $ip ok...
  else
    echo $ip failed...
  fi
  echo "finish------------------------------------" $ip
done <<____HERE
pass  22  root  1.1.1.1  test.txt
____HERE

any idea? thank you

share|improve this question
    
Try to run it using strace ./test.sh. This may give you a hint. –  Khaled Feb 2 at 7:58
    
Works for me on my CentOS Linux system. I'm guessing selinux is blocking execution. To disable selinux: setenforce 0 then try to run the script again. /etc/selinux/config sets whether selinux is enabled at system boot time. –  samiam Feb 2 at 8:14
    
@samiam I tried setenforce 0 but no result guy –  MortezaLSC Feb 2 at 8:15
    
Try this: echo 0 > /selinux/enforce –  samiam Feb 2 at 8:19
2  
@samiam: The correct thing to do if you suspect SELinux is to look for messages in /var/log/audit/audit.log and take appropriate action. That turning it off with setenforce 0 didn't solve the problem suggests that the problem lies elsewhere. –  Iain Feb 2 at 12:24

2 Answers 2

im guessing it has do with SELINUX. You are able to check the status with simply typing sestatus

share|improve this answer
    
If you read the extensice comments above the OP setenforce 0 and the problem didn't go away. –  Iain Feb 3 at 8:51
up vote 0 down vote accepted

I am running the script in /tmp directory as you see the result of ls is:

-rwxr-xr-x. 1 root root 1894 Feb  2 01:58 test.sh*

there is . after permissions which indicates that an SELinux security context applies to that file. so I copied test.sh in a directory else...

the problem was solved

I was in a directory where it might be a bad idea for executables to reside

ls -l /
drwxrwxrwt.   8 root root  1024 Feb  2 07:44 tmp/
share|improve this answer
    
Thanks, I learned something new (I wondered what that trailing dot was) –  samiam Feb 2 at 9:00
    
You don't say which version of CentOS but I have an out of the box CentOS 6.5 with SELinux enabled. If I create your file in /tmp, and make it executable it runs just fine. That you copied your file elsewhere and it works does not prove SELinux is involved. the setenforce 0 command should have enabled permissive mode, that this didn't solve the problem also suggests SELinux is not involved. You should check /var/log/audit/audit.log for AVC denied messages relating to your issue to prove SELinux is involved. –  Iain Feb 2 at 12:46
    
@ samiam your welcome –  MortezaLSC Feb 2 at 12:47
    
@Iain I have centos 6.5 ...why negative? what I understand: "I was in a directory where it might be a bad idea for executables to reside" may be something happend with my /tmp..This is my tmp output (drwxrwxrwt. 8 root root 1024 Feb 2 07:44 tmp/) –  MortezaLSC Feb 2 at 12:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.