Tried executing the .sh file present in the remote server with below code.
String command1="/home/support/test.sh";
try{
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
Session session=jsch.getSession(user, host, 22);
session.setPassword(password);
session.setConfig(config);
session.connect();
System.out.println("Connected");
Channel channel=session.openChannel("exec");
((ChannelExec) channel).setCommand(command1);
((ChannelExec) channel).setErrStream(System.err);
channel.connect();
channel.disconnect();
session.disconnect();
Content in shell script:
flname="12.log"
yest=`head -1 yes.txt`
filename=$flname.$yest
filename3=${filename}_prod3
scp [email protected]:/app/12/log/${filename}
/home/support/${filename}
mv ${filename} ${filename3}
today=$( date +"%Y-%m-%d")
java -jar /home/hybris/support/timeoutRprt.jar /home/support/${filename3}
After executing the script present in the remote server from the java class in my desktop, it doesn't create the files(output of jar file present in script) in remote server. But if I manually execute the script through putty, it produces the required files.
What might be case here?
InputStream in=channel.getInputStream(); channel.connect(); byte[] tmp=new byte[1024]; while(true){ while(in.available()>0){ int i=in.read(tmp, 0, 1024); if(i<0)break; System.out.print(new String(tmp, 0, i)); } if(channel.isClosed()){ System.out.println("exit-status: "+channel.getExitStatus()); break; } try{Thread.sleep(1000);}catch(Exception ee){} }yes.txt' for reading: No such file or directory scp: /app/12/log/form.log.: No such file or directory mv: cannot statform.log.': No such file or directory Error: /home/support/form.log._prod3 (No such file or directory)