begin process at 2012 02 11 14:18:26
  Trouver un code source :
 
dans
 
Accueil > Forum > 

JAVA / J2EE / J2ME

 > 

Divers

 > 

Général

 > 

éxecuter des scripts shell via une connexion ssh


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

éxecuter des scripts shell via une connexion ssh

lundi 23 mars 2009 à 18:21:40 | éxecuter des scripts shell via une connexion ssh

sirahmed

Salut Voila ce que je veux réaliser : -un client ssh sous windows que je le développedu genre de Putty . -Ce client doit exécuter des scripts shell sur un serveur ssh en unix J'ai essayé ceci mais ça ne fait que la connexion SSH : import com.jcraft.jsch.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class UserAuthKI{ public static void main(String[] arg){ try{ JSch jsch=new JSch(); String host=JOptionPane.showInputDialog("Enter username@hostname", System.getProperty("user.name")+ "@localhost"); String user=host.substring(0, host.indexOf('@')); host=host.substring(host.indexOf('@')+1); Session session=jsch.getSession(user, host, 22); // username and passphrase will be given via UserInfo interface. UserInfo ui=new MyUserInfo(); session.setUserInfo(ui); session.connect(); Channel channel=session.openChannel("shell"); channel.setInputStream(System.in); channel.setOutputStream(System.out); channel.connect(); //channel. } catch(Exception e){ System.out.println(e); } } public static class MyUserInfo implements UserInfo, UIKeyboardInteractive{ public String getPassword(){ return passwd; } public boolean promptYesNo(String str){ Object[] options={ "yes", "no" }; int foo=JOptionPane.showOptionDialog(null, str, "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); return foo==0; } String passwd; JTextField passwordField=(JTextField)new JPasswordField(20); public String getPassphrase(){ return null; } public boolean promptPassphrase(String message){ return false; } public boolean promptPassword(String message){ Object[] ob={passwordField}; int result= JOptionPane.showConfirmDialog(null, ob, message, JOptionPane.OK_CANCEL_OPTION); if(result==JOptionPane.OK_OPTION){ passwd=passwordField.getText(); return true; } else{ return false; } } public void showMessage(String message){ JOptionPane.showMessageDialog(null, message); } final GridBagConstraints gbc = new GridBagConstraints(0,0,1,1,1,1, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0,0,0,0),0,0); private Container panel; public String[] promptKeyboardInteractive(String destination, String name, String instruction, String[] prompt, boolean[] echo){ panel = new JPanel(); panel.setLayout(new GridBagLayout()); gbc.weightx = 1.0; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridx = 0; panel.add(new JLabel(instruction), gbc); gbc.gridy++; gbc.gridwidth = GridBagConstraints.RELATIVE; JTextField[] texts=new JTextField[prompt.length]; for(int i=0; i
lundi 23 mars 2009 à 18:23:02 | Re : éxecuter des scripts shell via une connexion ssh

sirahmed

import com.jcraft.jsch.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class UserAuthKI{ public static void main(String[] arg){ try{ JSch jsch=new JSch(); String host=JOptionPane.showInputDialog("Enter username@hostname", System.getProperty("user.name")+ "@localhost"); String user=host.substring(0, host.indexOf('@')); host=host.substring(host.indexOf('@')+1); Session session=jsch.getSession(user, host, 22); // username and passphrase will be given via UserInfo interface. UserInfo ui=new MyUserInfo(); session.setUserInfo(ui); session.connect(); Channel channel=session.openChannel("shell"); channel.setInputStream(System.in); channel.setOutputStream(System.out); channel.connect(); //channel. } catch(Exception e){ System.out.println(e); } } public static class MyUserInfo implements UserInfo, UIKeyboardInteractive{ public String getPassword(){ return passwd; } public boolean promptYesNo(String str){ Object[] options={ "yes", "no" }; int foo=JOptionPane.showOptionDialog(null, str, "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); return foo==0; } String passwd; JTextField passwordField=(JTextField)new JPasswordField(20); public String getPassphrase(){ return null; } public boolean promptPassphrase(String message){ return false; } public boolean promptPassword(String message){ Object[] ob={passwordField}; int result= JOptionPane.showConfirmDialog(null, ob, message, JOptionPane.OK_CANCEL_OPTION); if(result==JOptionPane.OK_OPTION){ passwd=passwordField.getText(); return true; } else{ return false; } } public void showMessage(String message){ JOptionPane.showMessageDialog(null, message); } final GridBagConstraints gbc = new GridBagConstraints(0,0,1,1,1,1, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0,0,0,0),0,0); private Container panel; public String[] promptKeyboardInteractive(String destination, String name, String instruction, String[] prompt, boolean[] echo){ panel = new JPanel(); panel.setLayout(new GridBagLayout()); gbc.weightx = 1.0; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridx = 0; panel.add(new JLabel(instruction), gbc); gbc.gridy++; gbc.gridwidth = GridBagConstraints.RELATIVE; JTextField[] texts=new JTextField[prompt.length]; for(int i=0; i
lundi 23 mars 2009 à 18:24:20 | Re : éxecuter des scripts shell via une connexion ssh

sirahmed

import com.jcraft.jsch.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class UserAuthKI{
  public static void main(String[] arg){
    
    try{
      JSch jsch=new JSch();

      String host=JOptionPane.showInputDialog("Enter username@hostname",                    System.getProperty("user.name")+ "@localhost");
                            
      String user=host.substring(0, host.indexOf('@'));
      host=host.substring(host.indexOf('@')+1);

      Session session=jsch.getSession(user, host, 22);

      // username and passphrase will be given via UserInfo interface.
      UserInfo ui=new MyUserInfo();
      session.setUserInfo(ui);
      session.connect();

      Channel channel=session.openChannel("shell");

      channel.setInputStream(System.in);
      channel.setOutputStream(System.out);

      channel.connect();

      //channel.
    }
    catch(Exception e){
      System.out.println(e);
    }
  }


  public static class MyUserInfo implements UserInfo, UIKeyboardInteractive{
    public String getPassword(){ return passwd; }
    public boolean promptYesNo(String str){
      Object[] options={ "yes", "no" };
      int foo=JOptionPane.showOptionDialog(null,
            str,
            "Warning",
            JOptionPane.DEFAULT_OPTION,
            JOptionPane.WARNING_MESSAGE,
            null, options, options[0]);
      return foo==0;
    }

    String passwd;
    JTextField passwordField=(JTextField)new JPasswordField(20);
  
    public String getPassphrase(){ return null; }
    public boolean promptPassphrase(String message){ return false; }
    public boolean promptPassword(String message){
      Object[] ob={passwordField};
      int result=
    JOptionPane.showConfirmDialog(null, ob, message,
              JOptionPane.OK_CANCEL_OPTION);
      if(result==JOptionPane.OK_OPTION){
  passwd=passwordField.getText();
  return true;
      }
      else{ return false; }
    }
    public void showMessage(String message){
      JOptionPane.showMessageDialog(null, message);
    }

    final GridBagConstraints gbc =
  new GridBagConstraints(0,0,1,1,1,1,
                GridBagConstraints.NORTHWEST,
                GridBagConstraints.NONE,
                new Insets(0,0,0,0),0,0);
    private Container panel;
    public String[] promptKeyboardInteractive(String destination,
                    String name,
                    String instruction,
                    String[] prompt,
                    boolean[] echo){
      panel = new JPanel();
      panel.setLayout(new GridBagLayout());

      gbc.weightx = 1.0;
      gbc.gridwidth = GridBagConstraints.REMAINDER;
      gbc.gridx = 0;
      panel.add(new JLabel(instruction), gbc);
      gbc.gridy++;

      gbc.gridwidth = GridBagConstraints.RELATIVE;

      JTextField[] texts=new JTextField[prompt.length];
      for(int i=0; i<prompt.length; i++){
  gbc.fill = GridBagConstraints.NONE;
  gbc.gridx = 0;
  gbc.weightx = 1;
  panel.add(new JLabel(prompt[i]),gbc);

  gbc.gridx = 1;
  gbc.fill = GridBagConstraints.HORIZONTAL;
  gbc.weighty = 1;
  if(echo[i]){
    texts[i]=new JTextField(20);
  }
  else{
    texts[i]=new JPasswordField(20);
  }
  panel.add(texts[i], gbc);
  gbc.gridy++;
      }

      if(JOptionPane.showConfirmDialog(null, panel,
                  destination+": "+name,
                  JOptionPane.OK_CANCEL_OPTION,
                  JOptionPane.QUESTION_MESSAGE) ==JOptionPane.OK_OPTION){
  String[] response=new String[prompt.length];
  for(int i=0; i<prompt.length; i++){
    response[i]=texts[i].getText();
  }
  return response;
      }
      else{
  return null;  // cancel
      }
    }
  }
}


Cette discussion est classée dans : public, string, host, joptionpane, gbc


Répondre à ce message

Sujets en rapport avec ce message

Serveur multiple qui redistribue les données à TOUT ses clients... [ par Hellway ] Voilà, mon problème est assez compliqué et je n'ai trouvé en aucun endroit de la toile réponse à ma question. Je tente donc le coup ici.Je bosse actue recuperer contenu de balise xml avec sax [ par lolofx ] salut, voila, je voudrais recuprer le contenu d'une balise xml choisi voila la sourcepour info nom correspond au nom de la balisefichier au nom du fic java, aidez moi je craque :'( [ par yasminexp ] slt voila ja deux fichier un Livre.java qui creer des livre avec nom auteur nbpage ... dedans un fonction compare2 qui est apler dans TestLivre.java, précision exo java sur implémentation [ par so250581 ] Bonjour, j'ai réalisé un sujet d'exercice sur les implémentations en java. J'ai mis les réponses que je pensais mais je n'en suis pas du tout sûr. Pou filtre [ par sheorogath ] slt tout le monde monde voila mon prob:j'ai creer un programme qui lit la premiere ligne d'un fichier avec un certaine extension mais je voudrais que applet print [ par neo1260 ] Salut, c encore moi avec mon probléme d'applet, j'ai laissé tombé la classe interne mais il me met une erreude compilation au niveau du book.append (p Communication entre 2 classes [ par cpraud ] Bonjour je cherche à faire communiquer 2 classesla 1ere extends Appletla 2ième extends la 1ere, et doit me renvoyer un paramètre de la page HTMLmais j Problème avec 1 exo java en JDBC, réalisation d'une classe ArrayDB et interface DataBasable [ par kheops06 ] Je suis débutant en Java et je dois réaliser un exo en JDBC, et je n'y comprend pas grand chose. Je dois réaliser une classe (ArrayDB) et une interfac Problème avec JDBC, à l'aide [ par kheops06 ] Je suis débutant en Java et je dois réaliser un exo en JDBC, et je n'y comprend pas grand chose. Je dois réaliser une classe (ArrayDB) et une interfac Problème, à l'aide!!!!!!!!!!!!!!!!!!! [ par kheops06 ] Je suis débutant en Java et je dois réaliser un exo en JDBC, et je n'y comprend pas grand chose. Je dois réaliser une classe (ArrayDB) et une interfac


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,749 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales