0

I have a shell script file with executable permissions:

-rwxr-xr-x   1 root   root       1147 Jan 26  2017 my_script

Even running it as root - fully qualified (path/to/file/my_script) I get the following error:

-bash: my_script: command not found

SELinux is being enforced and the context label is:

unconfined_u:object_r:var_t:s0

But even attempting to execute with SELinux disabled

Current mode:                   permissive

does not remedy the error. This script has executed as expected in the past.

What am I not understanding - why is this exception being encountered?

Reference: CentOS release 6.9

Roy Hinkley
  • 527
  • 4
  • 13
  • 20
  • 2
    It's unclear that you're calling this fully qualified, otherwise bash would print /path/to/my_script instead... Can you expand the context on that line? In which directory is the script located? – filbranden Mar 20 '18 at 22:34
  • You don't give enough details of what you're doing... Are you running my_script as root or a non-root user? What are the permissions of the directory that has my_script in it and its parents? What is the first line of my_script, does it start with #! and if so what interpreter does it use there? – filbranden Mar 20 '18 at 22:38
  • @FilipeBrandenburger The first line of the script starts with #! and has always ran as expected in the past. – Roy Hinkley Mar 20 '18 at 22:44
  • As @FilipeBrandenburger noted, the question text stating that you are running the script by entering a full path doesn't match the error message immediately after it. Please try running your script again and make your post consistent. – Michael Hampton Mar 20 '18 at 22:47
  • @FilipeBrandenburger - The error is originating from a line in the script - and that is why it only shows what I wrote. I have commented out that line in the script and it now is working as expected. – Roy Hinkley Mar 20 '18 at 22:58

1 Answers1

0

my_script is not in your PATH. So you have to provide the path to it when calling it directly.

./my_script
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • That's what I mean when I say fully qualified - I include the FULL PATH in the execution statement /path/to/file/script.sh. – Roy Hinkley Mar 20 '18 at 22:36
  • Really? You did not actually demonstrate this in your question. What you _did_ show indicates that you _did not_ provide the full path. But you posted a lot of stuff about SELinux that doesn't appear to be relevant. Please edit your question. – Michael Hampton Mar 20 '18 at 22:37