Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8256483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:52:27+00:00 2026-06-08T01:52:27+00:00

I’m establishing an SSH connection through JSch on Java and everything seemed to be

  • 0

I’m establishing an SSH connection through JSch on Java and everything seemed to be working fine, until I tried to run this .sh file. The shell script’s name is repoUpdate.sh and it’s very simple:

echo  ' ****Repository update****'
echo  ' Location: /home/cissys/repo/'
echo -e ' Command: svn update /home/cissys/repo/2.3.0'

svn update /home/cissys/repo/2.3.0

This is the output I get directly on the linux console with the proper response of the command:

[cissys@dsatelnx5 ~]$ repoUpdate.sh
 ****Repository update****
 Location: /home/cissys/repo/
 Command: svn update /home/cissys/repo/2.3.0

At revision 9432.

Now, here’s the Java code of my method with the SSH connection that tries to call this same file

public void cmremove()
{
    try
    {
        JSch jsch = new JSch();
        Session session = jsch.getSession(user, host, port);
        UserInfo ui = new SUserInfo(pass, null);
        session.setUserInfo(ui);
        session.setPassword(pass);
        session.connect();
        
        ChannelExec channelExec = (ChannelExec)session.openChannel("exec");
        
        InputStream in = channelExec.getInputStream();
        
        channelExec.setCommand("./repoUpdate.sh");
        channelExec.connect();
        
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line;
        int index = 0;
        
        while ((line = reader.readLine()) != null)
        {
            System.out.println(++index + " : " + line);
        }
        
        channelExec.disconnect();
        session.disconnect();
        
        System.out.println("Done!");
    }
    catch(Exception e)
    {
        System.err.println("Error: " + e);
    }
}

And the response I get is the following:

run:
1 :  ****Repository update****
2 :  Location: /home/cissys/repo/
3 :  Command: svn update /home/cissys/repo/2.3.0
Done!
BUILD SUCCESSFUL (total time: 2 seconds)

with no output or signs of execution on the svn command (At revision 9432) whatsoever.

I’m thinking it may be closing the session at some point, not letting the command execute properly. If the updateRepo.sh`` file would've had something like cp test.txt test_2.txt`, it would do it with no problem. But i only have this problem with this and some other specific .sh files.

Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:52:28+00:00Added an answer on June 8, 2026 at 1:52 am

    So here’s what I did.
    I added the exec 2>&1 at the top of the repoUpdate.sh file and added that piece of code to read the output error as @DanielMartin suggested, resulting on this:

    public void cmremove()
    {
        try
        {
            JSch jsch = new JSch();
            Session session = jsch.getSession(user, host, port);
            UserInfo ui = new SUserInfo(pass, null);
            session.setUserInfo(ui);
            session.setPassword(pass);
            session.connect();
    
            ChannelExec channelExec = (ChannelExec)session.openChannel("exec");
    
            InputStream in = channelExec.getInputStream();
    
            channelExec.setCommand("./repoUpdate.sh");
            channelExec.connect();
    
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            String line;
            int index = 0;
    
            while ((line = reader.readLine()) != null)
            {
                System.out.println(++index + " : " + line);
            }
    
            int exitStatus = channelExec.getExitStatus();
            channelExec.disconnect();
            session.disconnect();
            if(exitStatus < 0){
                System.out.println("Done, but exit status not set!");
            }
            else if(exitStatus > 0){
                System.out.println("Done, but with error!");
            }
            else{
                System.out.println("Done!");
            }
        }
        catch(Exception e)
        {
            System.err.println("Error: " + e);
        }
    }
    

    So that actually helped a lot. It confirmed that the command was, in fact, not executing correctly as I thought. I was getting this on my java output:

    run:
    1 :  ****Repository update****
    2 :  Location: /home/cissys/repo/
    3 :  Command: svn update /home/cissys/repo/2.3.0
    4 : ./repoUpdate.sh[6]: svn: not found [No such file or directory]
    Done!
    BUILD SUCCESSFUL (total time: 2 seconds)
    

    Then I tried modifying the repoUpdate.sh file, adding the absolute path for the svn command (Thank you, @ymnk)

    exec 2>&1
    echo  ' ****Repository update****'
    echo  ' Location: /home/cissys/repo/'
    echo -e ' Command: svn update /home/cissys/repo/2.3.0'
    
    /opt/subversion/bin/svn update /home/cissys/repo/2.3.0
    

    For my java, I got just what I was looking for:

    run:
    1 :  ****Repository update****
    2 :  Location: /home/cissys/repo/
    3 :  Command: svn update /home/cissys/repo/2.3.0
    4 : At revision 9443.
    Done!
    BUILD SUCCESSFUL (total time: 3 seconds)
    

    I found out that the $PATH I get from the session through java is not the same that I get directly on the linux console.
    So adding the svn path actually did the trick. Thank you very much for your help!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.