LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shells Quesiton (https://www.linuxquestions.org/questions/linux-newbie-8/shells-quesiton-282599/)

lamar_air 01-26-2005 04:38 PM

Shells Quesiton
 
Hi,

I'm using RedHat Fedora 9. I am trying to run some shell scripts from the terminal window but they aren't being recognized as shell scripts. How can I tell what I need to run them?

Thanks

jailbait 01-26-2005 04:45 PM

"I'm using RedHat Fedora 9. I am trying to run some shell scripts from the terminal window but they aren't being recognized as shell scripts. How can I tell what I need to run them?"

Did you set the permissions of your scripts to executable?

------------------
Steve Stites

mjrich 01-26-2005 04:45 PM

Code:

chmod u+x <filename>
Cheers,

mj

lamar_air 01-26-2005 04:46 PM

no, how do i set them?

mjrich 01-26-2005 04:53 PM

See post #3...

Cheers,

mj

lamar_air 01-26-2005 04:58 PM

It won't let me change the permissions of the script mon.

I was doing this is the lab at school. I believe its a solaris OS and it was working. Anyone know why I can't do it on my linux machine?
[jason@localhost jason]$ cd CSI3310
[jason@localhost CSI3310]$ cd lab1
[jason@localhost lab1]$ ls
calcloop code cploop lslog mon mon.c procmon tstcalc tstcp
[jason@localhost lab1]$ chmod u+x mon
chmod: changing permissions of `mon': Operation not permitted
[jason@localhost lab1]$ chmod u+x calcloop
[jason@localhost lab1]$ mon calcloop
bash: mon: command not found
[jason@localhost lab1]$ mon
bash: mon: command not found
[jason@localhost lab1]$ ls
calcloop code cploop lslog mon mon.c procmon tstcalc tstcp
[jason@localhost lab1]$

"mon" is a compiled program from the source code mon.c and I compiled it by "cc mon.c -o mon"

?????

mjrich 01-26-2005 05:14 PM

Quote:


"mon" is a compiled program from the source code mon.c and I compiled it by "cc mon.c -o mon"

Well there's your problem ;) If you've compiled it with cc (or gcc) then what you've created is a binary file, not a shell script. It could also be a monster, I guess.

So the problem is most likely just that by default you won't be able to run binaries in your home directory - this is just a safety measure against "bad things"(tm) happening. To force execution of a binary in your home directory, use
Code:

./ mon
EDIT:

What are the permissions on your mon ? (Type ls -lh mon). They could still be wrong, come to think of it.

Cheers,

mj

lamar_air 01-26-2005 08:12 PM

Hey thanks a lot. The ./mon worked perfectly.
The permissions are as follows:

[jason@localhost lab1]$ ls -lh mon
-rwxrwxr-x 1 jason jason 12K Jan 26 21:08 mon

So does that mean Read, Write, and "X" for exclusive access??

Thanks

mjrich 01-26-2005 08:26 PM

The permissions are generally in the order Owner - Group - Others. So the owner Jason has read, write and execute permissions, as do those in Jason's group, all others can read and execute only.

Cheers,

mj

lamar_air 01-26-2005 09:37 PM

I have another question:

My script i'm running now runs in the home directory by typing "./" infront of the script name but the processes that the script uses by using fork() and execl() don't seem to run. The output is supposed to look like this:

Monitoring /proc/15759/stat:

Time State SysTm UsrTm
0 Sleeping(memory) 0 0
1 Sleeping(memory) 0 0
2 Sleeping(memory) 0 0
3 Running 1 89
4 Sleeping(memory) 1 141
5 Zombie 3 566
Killing procmon.

But nothing shows up???? Can I do this from another directory other than home which allows these to run or is there a better way to do this? Anyone know? I have su access if that helps.
Thanks alot for the help so far!

mjrich 01-27-2005 05:47 PM

Depends on what you're trying to do, and what you're trying to call as part of your program. My guess is that you've either got a hard-coded path somewhere that is being fooled by running it from your home directory, or that you would need root permissions to access either the data or binaries that your program is attempting to run.

Hope this helps a bit.

Cheers,

mj

lamar_air 01-27-2005 08:35 PM

Here's what my professor said to do but i don't know how to do this (I tried typing the command "export PATH=.:$PATH" but that didn't seem to make any difference. Do you know how to do this mj or anyone else?


the scripts would not work, because they assume the PATH environment variable checks the current directory.

You can either correct the scripts (by replacing procmon by ./procmon), or better, by setting the PATH variable to include the current directory.

You can do that by typing

export PATH=.:$PATH

(this will work only for the current session)

or, even better by editing the file ~/.bashrc

mjrich 01-27-2005 08:43 PM

Should work.

Or, you could append the directory (your home directory in this case) to the appropriate line in /etc/profile. Look for the one beginning with "PATH". This does, of course, have slight security implications ;)

Cheers,

mj

jschiwal 01-27-2005 08:57 PM

The PATH variable by default doesn't contain the current directory '.' for security reasons.

What I do for scripts that I write myself is I have a ~/bin/ directory where I put the scripts.

The /etc/profile script on my system checks for $HOME/bin and adds it to the PATH variable if it exists:
[/code]
if test -z "$PROFILEREAD" ; then
PATH=/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin
if test "$HOME" != "/" ; then
for dir in $HOME/bin/$CPU $HOME/bin ; do
test -d $dir && PATH=$dir:$PATH
done
fi
[code]

If it hadn't done this, I could of added:
export PATH=PATH:$HOME/bin
to my ~/.profile script.

You don't want to have something like PATH=PATH:<New Path> in ~/.bashrc because .bashrc is run every time that a shell is started, and the PATH variable could grow with more identical entries added to the PATH variable.

lamar_air 01-27-2005 09:14 PM

This looks like exactly what I want to do but I need a few more instructions on how to set this up. I'm still pretty new to linux. Do I put that in a file i call "bin"?


All times are GMT -5. The time now is 09:07 AM.