????9??java?????linux?????????

import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;

import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;


/*
 * ??????linux?μ?vmstat???????????????д???????
 */
public class SSHTest {
 /**
  * @param args
  * @throws IOException
  */
 /*
  * ????????????????????????
  */
 static String hostName = "172.16.3.9";
 static int port = 2222;
 static String userName = "root";
 static String pwd = "kedats";
 
 
 public static void main(String[] args) throws Exception {
  // TODO Auto-generated method stub
  System.out.println("???????????");
  Connection conn = new Connection(hostName?? port);
  conn.connect();
  boolean isdenglu = conn.authenticateWithPassword(userName?? pwd);
  if (isdenglu) {
   System.out.println("ssh2??????");
  } else {
   System.out.println("??????");
  }
 
  //System.out.println("???????");
 
  Session ses = conn.openSession();
  ses.execCommand("vmstat 2");
  InputStream stdout = new StreamGobbler(ses.getStdout());
  BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

  FileWriter fw = new FileWriter("F:\vmstat.txt");
 
        while (true)    
        {    
            String line = br.readLine();    
            if (line == null)    
                break;
            System.out.println(line);
          
      fw.write(line+" "??0??line.length()+2);
      fw.flush();

//      OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("data2.txt"));
//      osw.write(line??0??line.length());
//      osw.flush();
//      PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("hello3.txt"))??true);
//      pw.println(line);
          
        }
      
  System.out.println("???н????"+ses.getExitStatus());
 
  //??????
  fw.close();
 
  ses.close();
  conn.close();
 }

}

????10??java??????????д????????

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class ToLog {
 
 static GregorianCalendar time = new GregorianCalendar();
// int year = time.get(Calendar.YEAR);     //???????????
// int day = time.get(Calendar.DAY_OF_MONTH);   //??????????
// int month = time.get(Calendar.MONTH)+1;    //?????????·?
// int weekDay = time.get(Calendar.DAY_OF_WEEK);  //?????????????
// int weekOfYear = time.get(Calendar.WEEK_OF_YEAR); //???????????????
// int weekOfMonth = time.get(Calendar.WEEK_OF_MONTH); //?????????μ?????
 
 private static final String getToday = time.get(Calendar.YEAR)+"-"+(time.get(Calendar.MONTH)+1)+"-"+time.get(Calendar.DAY_OF_MONTH)+"-";
 
 private static final String filePath = "C:\Documents and Settings\Administrator\workspace\Movision_script\logs\"+getToday+"log.html";
 
 //д?????
 public void toLog(String message){
  StackTraceElement stack[] = (new Throwable()).getStackTrace();
  StackTraceElement s = stack[1];
 
  String headerMessage = s.getClassName()+"."+s.getMethodName()+"()"+"??LineNum:"+s.getLineNumber()+"<br />??Message:&nbsp;&nbsp;&nbsp;&nbsp;";
 
  headerMessage = addDateTimeHeader(headerMessage);
  message = headerMessage + message + "<br /><br /><br />";
 
  FileWriter fw = null;
  File file = null;
 
  try{
   file = new File(filePath);
   fw = new FileWriter(file??true);
   fw.write(message);
  }catch(IOException ie){
   ie.printStackTrace();
  }finally{
   try{
    fw.close();
   }catch(IOException ie){
    ie.printStackTrace();
   }
  }
 }

 @SuppressWarnings("deprecation")
 public String addDateTimeHeader(String headerMessage) {
  String dateTimeHeader = new Date().toLocaleString()+"??";
  return dateTimeHeader += headerMessage;
 }
 
 
// public static void main(String args[]){
//  ToLog log = new ToLog();
//  String message = "????????";
//  log.toLog(message);
// }
}

????д???????????