Accueil > Forum > > > > éxecuter des scripts shell via une connexion ssh
é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
Livres en rapport
|
Derniers Blogs
[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko [FRAMEWORK 4] LES TASKS ET LE THREAD UI[FRAMEWORK 4] LES TASKS ET LE THREAD UI par fathi
Je viens de passer quelques temps au TechDay's et j'ai pu voir pas mal de session intéressante. Par contre une chose m'a un peu étonné lors de certaines de ces sessions qui abordaient les améliorations du framework .NET (donc le 4.5) : en gros, bea...
Cliquez pour lire la suite de l'article par fathi
Forum
AIDEAIDE par mlawah
Cliquez pour lire la suite par mlawah RE : J2EERE : J2EE par issats1987
Cliquez pour lire la suite par issats1987 RE : J2EERE : J2EE par abdouffff
Cliquez pour lire la suite par abdouffff RE : J2EERE : J2EE par issats1987
Cliquez pour lire la suite par issats1987
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|