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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
01-26-2005, 05:38 PM
|
#1
|
Member
Registered: Oct 2004
Posts: 37
Rep:
|
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
|
|
|
01-26-2005, 05:45 PM
|
#2
|
LQ Guru
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,376
|
"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
|
|
|
01-26-2005, 05:45 PM
|
#3
|
Senior Member
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046
Rep:
|
Code:
chmod u+x <filename>
Cheers,
mj
|
|
|
01-26-2005, 05:46 PM
|
#4
|
Member
Registered: Oct 2004
Posts: 37
Original Poster
Rep:
|
no, how do i set them?
|
|
|
01-26-2005, 05:53 PM
|
#5
|
Senior Member
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046
Rep:
|
See post #3...
Cheers,
mj
|
|
|
01-26-2005, 05:58 PM
|
#6
|
Member
Registered: Oct 2004
Posts: 37
Original Poster
Rep:
|
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"
?????
|
|
|
01-26-2005, 06:14 PM
|
#7
|
Senior Member
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046
Rep:
|
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 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.
|
|
|
01-26-2005, 09:12 PM
|
#8
|
Member
Registered: Oct 2004
Posts: 37
Original Poster
Rep:
|
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
|
|
|
01-26-2005, 09:26 PM
|
#9
|
Senior Member
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046
Rep:
|
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
|
|
|
01-26-2005, 10:37 PM
|
#10
|
Member
Registered: Oct 2004
Posts: 37
Original Poster
Rep:
|
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!
|
|
|
01-27-2005, 06:47 PM
|
#11
|
Senior Member
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046
Rep:
|
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
|
|
|
01-27-2005, 09:35 PM
|
#12
|
Member
Registered: Oct 2004
Posts: 37
Original Poster
Rep:
|
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
|
|
|
01-27-2005, 09:43 PM
|
#13
|
Senior Member
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046
Rep:
|
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
|
|
|
01-27-2005, 09:57 PM
|
#14
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
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.
|
|
|
01-27-2005, 10:14 PM
|
#15
|
Member
Registered: Oct 2004
Posts: 37
Original Poster
Rep:
|
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 01:14 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|