Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Updated

I find out that the path of jdk it using is wrong. eval: 1: /opt/Java/jdk1.6.0_25/jre/bin/java: not found the Java should be lower case java, how is that happen? When I run this script directly on server, it is just okay.


I'm trying to start or shutdown tomcat via a remote client.

On my server, I've got 3 different tomcat: tomcat1, tomcat2, and tomcat3.

Firstly, I've tried to run tomcat_path/bin/shutdown.sh to stop it via ssh, and the command is

ssh jake@1xx.3x.2x.1xx "cd /home/jake/tomcat2/bin;exec bash ./shutdown.sh"

both " and ' are tried, but do not work, the output is

eval: 1: /opt/Java/jdk1.6.0_25/jre/bin/java: not found

it seems that the shell script runs on my local client, because on server it has this file.

Is there any way to run a shell script on remote server correctly?

updated

I've run

ssh jake@1xx.xx.25.100 "sh -x /home/jake/tomcat/bin/shutdown.sh > /home/jake/tomcat.log 2>&1"

and the output in tomcat.log is :

+ PRG=/home/jake/tomcat/bin/shutdown.sh
+ [ -h /home/jake/tomcat/bin/shutdown.sh ]
+ dirname /home/jake/tomcat/bin/shutdown.sh
+ PRGDIR=/home/jake/tomcat/bin
+ EXECUTABLE=catalina.sh
+ [ ! -x /home/jake/tomcat/bin/catalina.sh ]
+ exec /home/jake/tomcat/bin/catalina.sh stop

eval: 1: /opt/Java/jdk1.6.0_25/jre/bin/java: not found
share|improve this question
    
You should just be able to run ... /home/jake/tomcat2/bin/shutdown.sh - what happens if you try that ? –  Iain Sep 18 '12 at 8:02
    
Still the same output eval: 1: /opt/Java/jdk1.6.0_25/jre/bin/java: not found –  bxshi Sep 18 '12 at 8:10
    
... sh -x /home/jake/tomcat2/bin/shutdown.sh > /home/jake/tomcat.log 2>&1 and post the log file here. –  quanta Sep 18 '12 at 8:14
    
@quanta still the same problem here –  bxshi Sep 18 '12 at 8:47
    
Could you check to execute via ssh jake@your.ip.add.here "/opt/Java/jdk1.6.0_25/jre/bin/java -version ? Is there an setenv.sh within your tomcat directory (to define the java path)? –  patricks Sep 18 '12 at 9:11

2 Answers 2

I find out that the path of jdk it using is wrong. eval: 1: /opt/Java/jdk1.6.0_25/jre/bin/java: not found the Java should be lower case java, how is that happen? When I run this script directly on server, it is just okay.

Because you've set the wrong environment variables somewhere (may be ~/.bashrc). bash reads the different startup files based on the different shell types. Keep in mind that:

  • ssh user@host 'command' is a non-interactive shell
  • whereas ssh user@host and run the command is an interactive shell.

http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files

share|improve this answer
    
I've tried ssh jake@125.39.25.100 ./home/jake/tomcat/bin/shutdown.sh but that runs the script on client, not the remote server. –  bxshi Sep 18 '12 at 10:17
    
Remove the dot before /home.... –  quanta Sep 18 '12 at 10:19
    
still the same problem. I think it is because the error shows eval: 1: /opt/Java/jdk1.6.0_25/jre/bin/java the path should be java but here is Java –  bxshi Sep 19 '12 at 3:53
    
grep '/opt/Java' ~/.bashrc ~/.bash_profile /etc/profile...? –  quanta Sep 19 '12 at 4:00
    
in /etc/profile there is export JAVA_HOME=/opt/java/jdk1.6.0_25, and the java is lower case. –  bxshi Sep 19 '12 at 9:45

It looks like an odd env variable not being set. For fun ... try to find any instance of "/opt/Java" ... an 'easy' way to do that is

find /etc -type f |grep -v ' ' | xargs grep /opt/Java

That may point to a bad config file on your system.

There could also be an odd (very odd) chance ... that you have a weird ssh config which allows client env variables to be passed (and set) on the server. [Rare situation ... but is theoretically possible]

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.