简体   繁体   中英

How to run java -jar command from Shell script from remote server?

pls help me in this immediately...

Problem with JAVA command in shellscript..

I have a script Cachereload.sh in one server which has the following command:

java -jar SingMgmnt.jar $4 $2 $3 sixdee sixdee $5

This is working very fine when i run it from the same server.

But i want to run this script from another server and i did it as

ssh oracle@192.168.0.72 'sh -c "./Cachereload.sh"'

which will prompt for the password, and after that it executes the script. But then I'm getting an error,

./CacheReload.sh: line 4: java: command not found

But only java command is not working i think.. bcoz pwd, ls and even mysql command is working fine from remote server itself..

Please help me out..

Thanking you All Akhil

This will be related to your ssh environment differing from the environment of an interactive shell. For example, assuming you're using bash your .bashrc file will only be sourced for interactive shell environments. So if you're setting your PATH variable within your .bashrc file it will only take effect for interactive shells.

A simple workaround is to refer to the absolute path of the java binary within your Cachereload.sh script.

what happens when the oracle user runs this command on the server, not via the one line ssh.

Its quite likely that java is not in the PATH for this user (possibly not install at all).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM