LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-19-2006, 11:39 PM   #1
SBN
Member
 
Registered: Jul 2006
Distribution: UBUNTU, CentOS, FEDORA 8
Posts: 474

Rep: Reputation: 30
script wont work?


-hello guys i wrote a script containing this line

Quote:
/usr/local/squid/sbin/squid -k shutdown
and then copied it to my bin directory in my home directory. but when i execute it outsite the bin directory it says command not found. i wrote some small scripts, i used the some process all works excepts for the one i stated above. what could be wrong?
 
Old 11-20-2006, 12:52 AM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Is your bin directory in your path (type echo $PATH)? Is the file executable (type ls -l /home/yourusername/bin/scriptname)? Do you have something like #!/bin/sh as the first line of the script? What do you get when you type ls -l /usr/local/squid/sbin/squid? Does your user account have permissions to the /usr/local/squid/sbin directory?

Sorry it's just a lot of questions...
 
Old 11-20-2006, 05:34 AM   #3
GNUlancer
Member
 
Registered: Oct 2006
Location: Russia
Distribution: Slax KillBill
Posts: 59

Rep: Reputation: 15
Cool

Code:
cd your-bin-directory-in-your-home-directory
chmod a+x your-script-name      # permit ALL users to execute this file, see man chmod
PATH=$PATH:your-bin-directory-in-your-home-directory      # include your directory in the PATH environment variable. Bash is searching for executables in all PATH dirs every time you type your command or run a script.
that should work. In fact you don't need to put the interpreter's path into your script, but it's worth to do for consistensy.

The above sequence will only change PATH in your current bash session, e.g. if you run other instance of bash you will need to set it again. To place your directory in PATH in all new bash sessions for all users, enlist it in the /etc/profile file in the export command. Or you can simply add this code to your ~/.bash_profile, which runs only for you.
 
Old 11-20-2006, 05:37 AM   #4
GNUlancer
Member
 
Registered: Oct 2006
Location: Russia
Distribution: Slax KillBill
Posts: 59

Rep: Reputation: 15
To find out, how bash works, try man bash
Use '/' for searching, 'n' to go to the next result, and 'h' for help on other browsing functions.
Have fun
 
Old 11-21-2006, 01:02 AM   #5
SBN
Member
 
Registered: Jul 2006
Distribution: UBUNTU, CentOS, FEDORA 8
Posts: 474

Original Poster
Rep: Reputation: 30
- i tried putting my bin directory into the PATH using
Quote:
export PATH=$PATH:~/bin
and
Quote:
PATH=$PATH:~/bin
only both works i can now execute the command my theres a new problem the PATH that i specify is not being saved. whenever i exit the terminal open it again and excute the the script the command not found shows up again and when i check the echo $PATH my bin directory is not there. so i have to set it again. is there i can do whith this?
 
Old 11-21-2006, 05:09 AM   #6
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
If you're using bash as your shell, you should be able to put the following in ~/.bash_profile:
Code:
export PATH=$PATH:~/bin
You might have to expand the '~'...
 
Old 11-21-2006, 07:41 AM   #7
GNUlancer
Member
 
Registered: Oct 2006
Location: Russia
Distribution: Slax KillBill
Posts: 59

Rep: Reputation: 15
See my post ^^

you should put it in the /etc/profile for all users (it executes first) OR in ~/.bash_profile only for you
 
Old 11-21-2006, 08:35 PM   #8
SBN
Member
 
Registered: Jul 2006
Distribution: UBUNTU, CentOS, FEDORA 8
Posts: 474

Original Poster
Rep: Reputation: 30
-this is my echo $PATH

Quote:
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games
-i added my bin directory using these commands

Quote:
export PATH=$PATH:/home/administrator/bin or
export PATH=$PATH:~/bin or
PATH=$PATH:/home/administrator/bin or
PATH=$PATH:~/bin
all have the same output when i check my PATH
Quote:
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:/home/administrator/bin
-this works actually but when i close the terminal and check my PATH again it return to this

Quote:
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games
-its not saving, why is that?

-i think i will try manually editing my .bash_profile
this is its content:

Quote:
# ~/.bash_profile: executed by bash(1) for login shells.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/login.defs
#umask 022

# include .bashrc if it exists
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# set PATH so it includes user's private bin if it exists
if [ -d ~/bin ] ; then
PATH=~/bin:"${PATH}"
fi
-i will try adding this:

Quote:
PATH=$PATH:/home/administrator/bin
-so my bash_profile will now be like this:

Quote:
# ~/.bash_profile: executed by bash(1) for login shells.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/login.defs
#umask 022

# include .bashrc if it exists
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# set PATH so it includes user's private bin if it exists
if [ -d ~/bin ] ; then
PATH=~/bin:"${PATH}"
fi

PATH=$PATH:/home/administrator/bin
-is it correct?
 
Old 11-21-2006, 08:54 PM   #9
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
I'd use:
Code:
export PATH=$PATH:/home/administrator/bin
 
  


Reply



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
My script wont run on boot Unicron Ubuntu 2 06-18-2006 11:19 AM
ok got fglrx 2d to work, now why wont 3d work? bvav22 Linux - Software 1 05-01-2005 06:25 PM
FALCONS EYE (nethack) FAILS ON STARTUP, use to work, wont work even after reinstall roorings Linux - Software 0 10-08-2003 10:39 PM
Shutdown script wont physically turn off my system... cav Slackware 2 09-13-2003 02:06 AM
Why wont it work?? Nrub Linux - Distributions 1 11-18-2002 07:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:17 AM.

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