1833744 Members
2692 Online
110063 Solutions
New Discussion

Command not found error!

 
SOLVED
Go to solution
Becke
Super Advisor

Command not found error!


Hi Guys,

I have an error message in hp server while running a korn shell script which has been working fine for many many years and hasn't been changed.

this script has acl permission bit set and someone has removed the acl permissions from it which makes sense why script not working anymore, however when I changed the permission and gave chmod 777 to this script it complains about a program file not found whick gets kicked off within that korn shell script, this program file does exist in the directory and always been there, below is the error message...

Error "/usr/local/bin/spool_menu.ksh[125]: realroot: not found"

I have checked the system PATH and /usr/local/bin is there, any ideas about the above error????
11 REPLIES 11
Geoff Wild
Honored Contributor
Solution

Re: Command not found error!

What is on line 125 of /usr/local/bin/spool_menu.ksh?

It is saying it can't find "realroot"

Try
which realroot

You might have to set the full path in the script instead...

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Steven E. Protter
Exalted Contributor

Re: Command not found error!

Shalom Raf,

Perhaps the file is hidden from the user.

Check the permissoins on the program:

The error is on line 125. It may be misreportting another program that it calls.

Throw a set -x right after the shell statement in the script and you may get a better idea of what the problem is.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: Command not found error!

Hi Raf:

Make sure that the *directory* --'/usr/local/bin' -- is readable and executable by the user running the script that gives the error.

Regards!

...JRF...
Becke
Super Advisor

Re: Command not found error!


Hi Steven/Geoff,

Thanks for the quick responses guys, as this is a production problem, I had to get things going, so i have set the full path name of the command in the script which has got it working before I post this message, but this is not really resolving the problem and I want to find out the root cause as there are many other scripts in production which calls realroot and realroot program doesn't have the full path name in those scripts and obviously I don't want to manually set the full path name everywhere for realroot.

When I typed in which realroot, it gives me the full path name ie (/usr/local/bin/realroot)

I have reset the permissions on realroot (chmod 777 realroot)but when I run the script without the full path name it gives the same error ie (Error "/usr/local/bin/spool_menu.ksh[125]: realroot: not found")

Here is the error message when i put in set -x right below the shell statement in the script.

Enter a space separated list of ids to cancel, or (P) to select a printer
:- + read IDS
+ print Clear queue for printer - Please enter printer name : \c
Clear queue for printer - Please enter printer name : + read PRINTER
esd
+ [[ p = @(q|Q ]]
+ [[ esd = @(q|Q ]]
+ [[ -n esd ]]
+ realroot cancel esd -e
/usr/local/bin/spool_menu.ksh[126]: realroot:not found
+ print \n\nHit to continue :- \c
Hit to continue :- + read REPLY..
end

Guys this script actually deletes jobs sitting on the printer queue...

Cheers
Raf




Geoff Wild
Honored Contributor

Re: Command not found error!

How about add

export PATH=$PATH:/usr/local/bin

to top of script?

BTW - I wouldn't have 777 on any script - 775 should be sufficient...

It also may be that the script needs to be setuid

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Bill Hassell
Honored Contributor

Re: Command not found error!

Changing a problem script to 777 never solves anything and has now made your script vulnerable to being trashed by anyone on your computer. Change it back to at least 755 to protect the contents. Note that changing the permission of a script won't change it's ability to search a directory (which is how the "not found" error is generated. It also does not matter what permissions realroot has -- even if it was 777 or 000 permission, the only way an error "not found" will occur is that the directory cannot be searched by the script, or that realroot is actually a symlink that points to a non-existant file.

Just a note about PATH and scripts: Never use the PATH that the parent program (shell) uses. You have no control over it since any user (including root) can modify it, either on purpose or by accident. Instead, the first few lines in your script should have:

export PATH=/usr/bin:/usr/local/bin

This takes eefect only for the current script and disappears when the script terminates. If you need anotgher path, add it to your script.

Another note about which and whereis. Neither command is useful in scripting or debugging. You want to know exactly what the shell will do when a a text string is seen. The commands which and whereis will fail to locate "for" and "done", yet they are perfectly valid items in a script. You want to use whence, or better yet, whence -v. To make things easier, whence -v is aliased to type in ksh and POSIX-sh. So to see what the shell will find when you refer to realroot, use this command:

type realroot

You may be (unpleasantly) surprised to see that it has been aliased, something that which and whereis will never tell you.

And while you're at it, add set -u next to the PATH statement in your script. It prevents disastrous consequences due to spelling errors.


Bill Hassell, sysadmin
Bill Hassell
Honored Contributor

Re: Command not found error!

And to explain why /usr/local/bin/realroot works but realroot does not again points to the permissions of /usr /usr/local and /usr/local/bin. Note that HP-UX has had bad permissions on the /usr/local directories for years (ie, 777) when they should be identical to /usr/contrib. Someone may have inadvertantly changed 777 to 700 or 744. The reason that a full pathname works is that no search is needed -- the entire path has been given. Without a full path, the /usr/local/bin directory must be searched to find realroot.


Bill Hassell, sysadmin
Becke
Super Advisor

Re: Command not found error!


Hi Team,

Thanks to everyone's prompt response and help, I have checked the permissions on /usr/local and /usr/local/bin directories and the user has access to it.

Bill and Geoff your suggestion worked as I have added the "export PATH=/usr/bin:/usr/local/bin" statement in script and its working like a charm, I have also added the path statement in user's .profile so it searches for the right directory as user's .profile kicks off the shell script and from the main menu user takes an option which kicks off this script which had problems.

I have changed the permissions to 777 temporarily just to test the script. I have now changed it back to 755..

Bill thanks for your detailed explanation, I have learned again something new today from our team. I will now assign points

Cheers,
Raf

Arunvijai_4
Honored Contributor

Re: Command not found error!

Hi Raf,

Whenever you write any scripts, make sure you use absolute path or export PATH on top of the script to your special or custom commands. It is always a good practice. Just a thought i should share.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Muthukumar_5
Honored Contributor

Re: Command not found error!

Exporting a binary directory path into PATH will not solve the problem always.

upper level directory permission for execution is needed to be check

If there are binaries with same name but in different location then PATH variable decides which one has to be executed. We have to be sure on that else,

OLDPATH=$PATH
PATH=...:..:..

....


export PATH=$OLDPATH

use this in your script.

PS: You've got the solution. Assing 0 points to this ;)

--
Muthu

Easy to suggest when don't know about the problem!
Becke
Super Advisor

Re: Command not found error!


Thanks as always Arun/Muthu for your input.....

As the problem has now been resolved but I'd love to give you a bottle of coke and a choclate along with the points:)....