1834020 Members
3038 Online
110063 Solutions
New Discussion

command not found ...

 
dave broome_2
Advisor

command not found ...

This crosses over into a few vendors are so i am trying all of them to see if I can fix the problem. I have written and successfully run an Oracle Java stored procedure to run an O/s command, this runs from an Oracle database SQL prompt. On a previous machine running HP 11i it ran fine, on the new one it will only run a very restricted number of commands. LS, PWD are fine but I get "not found" on anything like MV and CP. I know the procedure has compiled ok because it runs a few commands fine. Any thoughts from an OS perspective what could cause such a thing?

Any help gratefully received.

Dave
35 REPLIES 35
Massimo Bianchi
Honored Contributor

Re: command not found ...

I suggest you to change the shell.

Some commands, see "man ..." for details, are built in the sheel, while others are external.


I think that your plsql procedure works only with the built-in commands, and not with the external ones.

You can try adding ENV variables, to add search path, but i suspect the firt reason.

Massimo
Mark Grant
Honored Contributor

Re: command not found ...

You could be running a "restricted" shell. If you log into the machine type "echo $0" and if it comes back with "-rsh" that will be the problem.

Most likely though, it is something in the .profile of the user that starts the application. It would seem to be intentional though because "ls" and "mv", by default are in the same directory. See if you can see if you are running your own copies of the tools you can use an not the system ones. Try /usr/bin/mv instead of just mv. One more thing, see if you have a "." in the beginning of your PATH.
Never preceed any demonstration with anything more predictive than "watch this"
dave broome_2
Advisor

Re: command not found ...

I very much get the feeling that it is running a "restricted" shell. The challenge is that I only get the problem from a SQL prompt, if I telnet to the machine as Oracle I can run all of the commands normally, as this user I did the echo $0 and got -sh. When I try and put that command into the execute command procedure from the SQL prompt it just echos back $0 as a string as shown below
SQL> exec executecmd('/usr/bin/echo $0');
OUT>$0
ExitValue: 0

It's as if it is only allowing a "restricted" login to certain users?? Does this make any sense? I don't know what user Oracle uses to run it's java stuff remotely. If it is restricted how do I make it un-restricted?
Mark Grant
Honored Contributor

Re: command not found ...

try executing /usr/bin/sh -c "echo $0"

This forces a new shell to start and the echo command will be run by that shell.
Never preceed any demonstration with anything more predictive than "watch this"
dave broome_2
Advisor

Re: command not found ...

this returns a blank as shown below ...

SQL> exec executecmd('/usr/bin/sh -c "echo $0"');
OUT>
ExitValue: 0
Massimo Bianchi
Honored Contributor

Re: command not found ...

try this, should get rid of any problem:

exec executecmd('/usr/bin/csh -s "cp first second"');



Massimo
Mark Grant
Honored Contributor

Re: command not found ...

Dave,

In that case try Massimo's thing. You can use the csh -s or the sh -c as in my previous post. Whichever "floats your boat"
Never preceed any demonstration with anything more predictive than "watch this"
dave broome_2
Advisor

Re: command not found ...

I tried both of those and my SQL session just hangs and the second file has not been created??
Massimo Bianchi
Honored Contributor

Re: command not found ...

sorry, i think that I mis-writed.

exec executecmd('/usr/bin/csh -c "cp first second"');


otherwise, with the -s, the shell will wait for other input.


Massimo


dave broome_2
Advisor

Re: command not found ...

are the double quotes necessary?
Mark Grant
Honored Contributor

Re: command not found ...

I am afraid they are. Otherwise you will only get the first part of the command.
Never preceed any demonstration with anything more predictive than "watch this"
dave broome_2
Advisor

Re: command not found ...

I think the quotes are in the right place and I get ..
SQL> exec dave
/usr/bin/csh -c
"cp /home/oracle/files/a.a /home/oracle/files/b.b"
ERR>Unmatched "
ExitValue: 1


Graham Cameron_1
Honored Contributor

Re: command not found ...

Hace you done (as DBA) ?
SQL> GRANT JAVAUSERPRIV TO YOUR_USER;
--
-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
dave broome_2
Advisor

Re: command not found ...

yep.
Mark Grant
Honored Contributor

Re: command not found ...

Will it work without the single quotes as in

exec executecmd(/usr/bin/sh -c "cp file1 file2");

Never preceed any demonstration with anything more predictive than "watch this"
dave broome_2
Advisor

Re: command not found ...

no, to get it to work with Oracle syntax constraints I built the string up separately so I could include the double quotes but it didn't work. I ran the command from an O/S prompt and it worked fine, so I just have to figure out how to get to run from within Oracle.
Graham Cameron_1
Honored Contributor

Re: command not found ...

I'm trying to replicate your scenario using code downloaded from MetaLink.
Haven't got it working yet but there is a lot of information being logged to USER_DUMP_DEST_AREA.
Does this help?
-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
dave broome_2
Advisor

Re: command not found ...

thanks for trying but sorry no help.
Massimo Bianchi
Honored Contributor

Re: command not found ...

Unmatched "


Looks like a sintax problem...

i suggest to check using and echo:

exec executecmd('/usr/bin/sh -c "echo \"cp file1 file2\""');

we want this output:
"cp file1 file2"


untill we fix this there is no chance to get it work.


What is the output you get ?



Massimo
Graham Cameron_1
Honored Contributor

Re: command not found ...

Dave
Try this
--
select * from dba_java_policy
where GRANTEE =
--
Look at the NAME and ACTION fields.
Compare with the working system.
I have had to add grants to allow my script to work.
(The clue was in the .trc files under USER_DUMP_DEST).
Hope that helps.
-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
dave broome_2
Advisor

Re: command not found ...

excuse my ignorance, here is the output. I'm not sure if I have all of the quotes in the right place. My guess is that the Oracle procedure can't cope with the double quotes.
dave broome_2
Advisor

Re: command not found ...

I get no rows returned from both the working and non-working systems. I am now checking for trace files.
Graham Cameron_1
Honored Contributor

Re: command not found ...

This may help.
http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96656/security.htm#1006434
Can't do any more on this today - work calls - although this is much more interesting!!
-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Massimo Bianchi
Honored Contributor

Re: command not found ...

Attached a VERY usefull docs with many examples of the use of execcmd from java, with debugging tips.

Massimo