Solved

Can't run executable with file and directory permissions set for executable

Posted on 2004-03-22
7
395 Views
Last Modified: 2010-04-20
Just started poking around some linux distros (knoppix, libranet, mandrake) and I'm mystified why I cant run a small 'hello world' kind of executable. I chmod'd the file and directory to 777, tried doing it with root account, all I get is a command not found errors. Doing a ls -al I can see that the file and directory do have executable permissions. Bash recognizes the file as an executable by showing it in green. The file is in my /home directory. I finally got it to work by using root and placed the file in my /sbin directory. What is preventing me from running under /home ????
0
Comment
Question by:Jebtrix
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 2

Author Comment

by:Jebtrix
ID: 10654895
Nevermind I figured out I needed the full path name unless its in $PATH. Let me rephrase the question, is there anyway I can run the executable without full path and without adding current directory to global $PATH var? Like autoappending path if file is in current folder or something along those lines.
0
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 50 total points
ID: 10654925
If you don't want to put "." on the search path, then just do:

./progname ...

0
 
LVL 21

Expert Comment

by:tfewster
ID: 10655750
Don't forget to remove the test executable from /sbin & change the directory permissions back to 755 -
It's not too important if only you use this machine, but it''s never too early to learn good habits ;-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Assisted Solution

by:Alf666
Alf666 earned 50 total points
ID: 10660124
I'd like to add my two cents here on different topics :

1) Executing with the right path :

- Using full path : /home/myname/myproggie
- Using relative path : ./myproggie or ../myproggie or ./myproggies_dir/myproggie

The PATH variable will only be used if the prog can't be found directly with the command you gave (including a path).

2) The files and dirs access rights

Directories will never need 777.
1 will allow you to cd inside it (or access/execute) whatever file is inside it.
2 will allow you to write inside of it. Which means you can't create or delete a file from it. But, if you have write access on a file, you will be able to modify it.
4 will allow you to read it (usefull to know what's inside of it)

In fact, the access rights on a directory will allow you to modify it's structure (directories used to be some kind of special files, so to say).

An exe will never need 777 either. An executable will need 1 at least. A shell script will need 1 + 4 (it needs to be read before beeing evaluated).

And, in the future, you might encounter similar problems if you write a shell script which has the proper access rights but does not begin with a shell command to help the system identify which shell command will be used to "run" it. So, all your scripts have to begin with :
#!/bin/bash

(for example, assuming bash is in /bin, and you want to use bash).

3) A few infos about security

To reply to your question, you can add "." to your PATH. But :

If you ever care about security, you should avoid having "." in your PATH. If you really want it, it should be the last element. If you do, and you work as root, any clever hacker might add a command like "ls" in /tmp for example, and, the next time you cd to /tmp, you will execute the malicious program.

So, the simplest suggestion is :

export PATH=${PATH}:.
(assuming your default shell is bash).

You could add this line to your .bashrc or .bash_profile (in your home directory).
0
 
LVL 9

Expert Comment

by:Alf666
ID: 10682471
Hi, did any of these answer reply to your question ?
0
 
LVL 21

Expert Comment

by:tfewster
ID: 10683117
IMHO - brettmjohnson gave the first valid answer, but Alf666 gave an excellent tutorial on paths & permissions.  Unless Jebtrix wants to request a refund at http://www.experts-exchange.com/Community_Support/  I suggest splitting the points between them ;-)
0
 
LVL 2

Author Comment

by:Jebtrix
ID: 10715947
Thanks for the added depth Alf666.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
plsql job on oracle 18 109
Certificate Request CentOS/Apache 1 57
SMTP log file for IMSVA 5 75
leap year shell script 10 55
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question