Not Found Message In Script Execution

Unix Solaris, version 5.10, ksh. 

Problem:

I have a script with environment variables which I have to execute prior to other scripts. The script belongs to userA and when I log in, and cd to its directory. It doesn't work and the following message appears:

Code:
$ . load_env.sh
ksh: load_env.sh:  not found
The strange thing is that if I log in with a different user, userB, and then I do: 

Code:
$ su - userA
Then cd to my script's directory and execute it, it works.

The command env returns similar results in both cases.

Have tested this:

Code:
$ . ./load_env.sh

In both cases the PATH variable is the same:

Code:
$ echo $PATH
/usr/bin::/opt/EMCpower/bin:/etc/emc/bin:/etc

if I use . ./ it works. However, I would like to have it working the other way (<dot><space>), since, this is not the only machine (the other 4 machines are working) with this configuration and the operations personnel have already been trained.

Solution:

The highlighted blank entry in $PATH is the equivalent of having a dot "." in $PATH (which is a known security issue). When your current working directory is the same as the script it will execute if the script is executable and the user has permission to execute the script.

Code:
Example.  See the effects of an extra colon in $PATH.

myscript.sh
echo "working"

PATH=/usr/bin
myscript.sh
sh: myscript.sh:  not found.

PATH=/usr/bin:
myscript.sh
working

PATH=:/usr/bin
myscript.sh
working

It is more secure to create a central scripts directory with the scripts owned by root and each script with permissions 755. Then append the scripts directory to $PATH in each user's .profile. Where there is a mixture of user groups on a machine it can be necessary to set the permissions to 750 and use secondary groups to control who can execute a script.

A central script can then be executed with the command you describe. We use this technique extensively for ease of maintenance. Also if a user owns a script they can change or delete it !

Have a Unix Problem
Unix Forum - Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.