Bonjour.

IL s'agit de lancer un script qui est sur un serveur linux depuis une appli java. J'ai trouvé j2ssh qui semble correspondre à mon besoin.
J'arrive bien à accéder au serveur distant, à me déplacer dans l'arborescence et copier des fichiers.
Par contre, je ne vois pas comment je peux exécuter un script. La doc n'est pas trés bavarde sur le sujet.

Voilà mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
ConfigurationLoader.initialize(false);
// Make a client connection
SshClient ssh = new SshClient();
      ssh.setSocketTimeout(30000);
      SshConnectionProperties properties = new SshConnectionProperties();
      properties.setHost("172.16.10.111");
      properties.setPort(22);
      ssh.connect(properties, new IgnoreHostKeyVerification());
 
PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
     pwd.setUsername("scott");
     pwd.setPassword("tiger");
 
int result = ssh.authenticate(pwd);
 
      if (result == AuthenticationProtocolState.COMPLETE)
	  {
	    System.out.println ("Connection OK...");
        SessionChannelClient session = ssh.openSessionChannel();
        // Now launching the script: 
        if (session.startShell())
        {
			session.executeCommand("/ora/usr3/local/script.sh");
			System.out.println ("Execution terminée");
        }
         session.close();
 
	}
        else
 
		 System.out.println("Failed to start the users shell");
		ssh.disconnect();
...

Quand j'execute sous NetBeans, j'ai ceci:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
INFO: Channel request succeeded
24 mars 2009 17:48:22 com.sshtools.j2ssh.session.SessionChannelClient executeCommand
INFO: Requesting command execution
24 mars 2009 17:48:22 com.sshtools.j2ssh.session.SessionChannelClient executeCommand
Execution terminée
INFO: Command is /ora/usr3/local/script.sh
24 mars 2009 17:48:22 com.sshtools.j2ssh.connection.ConnectionProtocol sendChannelRequest
INFO: Sending exec request for the session channel
24 mars 2009 17:48:22 com.sshtools.j2ssh.connection.ConnectionProtocol sendChannelRequest
INFO: Waiting for channel request reply
24 mars 2009 17:48:22 com.sshtools.j2ssh.connection.ConnectionProtocol sendChannelRequest
INFO: Channel request failed
24 mars 2009 17:48:22 com.sshtools.j2ssh.connection.ConnectionProtocol closeChannel
INFO: Local computer has closed channel 0[session]
24 mars 2009 17:48:22 com.sshtools.j2ssh.connection.ConnectionProtocol onStop
INFO: Closing all active channels
24 mars 2009 17:48:22 com.sshtools.j2ssh.connection.ConnectionProtocol onStop
INFO: thread has 1 active channels to stop
24 mars 2009 17:48:22 com.sshtools.j2ssh.connection.Channel close
...
Je suppose que qq chose ne va pas (forcément, lol) mais je n'ai aucune idée de ce qui coince.
Merci pour votre aide.