LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-26-2005, 05:38 PM   #1
lamar_air
Member
 
Registered: Oct 2004
Posts: 37

Rep: Reputation: 15
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
 
Old 01-26-2005, 05:45 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,376

Rep: Reputation: 564Reputation: 564Reputation: 564Reputation: 564Reputation: 564Reputation: 564
"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
 
Old 01-26-2005, 05:45 PM   #3
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
Code:
chmod u+x <filename>
Cheers,

mj
 
Old 01-26-2005, 05:46 PM   #4
lamar_air
Member
 
Registered: Oct 2004
Posts: 37

Original Poster
Rep: Reputation: 15
no, how do i set them?
 
Old 01-26-2005, 05:53 PM   #5
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
See post #3...

Cheers,

mj
 
Old 01-26-2005, 05:58 PM   #6
lamar_air
Member
 
Registered: Oct 2004
Posts: 37

Original Poster
Rep: Reputation: 15
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"

?????
 
Old 01-26-2005, 06:14 PM   #7
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
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

Last edited by mjrich; 01-26-2005 at 06:17 PM.
 
Old 01-26-2005, 09:12 PM   #8
lamar_air
Member
 
Registered: Oct 2004
Posts: 37

Original Poster
Rep: Reputation: 15
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
 
Old 01-26-2005, 09:26 PM   #9
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
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
 
Old 01-26-2005, 10:37 PM   #10
lamar_air
Member
 
Registered: Oct 2004
Posts: 37

Original Poster
Rep: Reputation: 15
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!
 
Old 01-27-2005, 06:47 PM   #11
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
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
 
Old 01-27-2005, 09:35 PM   #12
lamar_air
Member
 
Registered: Oct 2004
Posts: 37

Original Poster
Rep: Reputation: 15
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
 
Old 01-27-2005, 09:43 PM   #13
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
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
 
Old 01-27-2005, 09:57 PM   #14
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.

Last edited by jschiwal; 01-27-2005 at 10:01 PM.
 
Old 01-27-2005, 10:14 PM   #15
lamar_air
Member
 
Registered: Oct 2004
Posts: 37

Original Poster
Rep: Reputation: 15
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"?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hi, one quesiton! malc Linux - Newbie 7 12-01-2005 03:20 AM
KUDZU quesiton waelaltaqi Linux - General 1 10-05-2005 04:15 PM
Quesiton about Scripts caps_phisto Linux - General 2 12-17-2004 10:50 AM
Dumb gkrellm quesiton stunter Linux - Software 2 06-21-2004 01:19 AM
Quesiton regarding Xinetd Ghost of War Linux - Security 1 04-20-2004 06:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration