2014年11月12日水曜日

VMwareにてandroidインストール時の解像度

Vmwareにてandroidをインストールして解像度を変更したいとき

デバッグモードにて起動
# mount -o remount,rw /mnt
# vi /mnt/grub/menu.lst
引数の最後にvga=794とつけると1280×1024になる
vga=askとつけると一覧で確認したうえで選択できる模様

2014年11月4日火曜日

Tera Termマクロ コマンドリスト(cmd.txt)を読み込んで実行

Tera Termマクロ コマンドリスト(cmd.txt)を読み込んで実行
コマンド実行 一回ごとに実行していか確認
;=========================================================== 
;; 接続報ホスト/ユーザ名設定 
HOSTADDR = '192.168.109.129' 
USERNAME = 'root' 
;=========================================================== 
;; ①接続先ホストのパスワードを入力 
MASSAGE = 'HOST : ' 
strconcat MASSAGE HOSTADDR 
strconcat MASSAGE ' / USER NAME : ' 
strconcat MASSAGE USERNAME 
passwordbox MASSAGE 'Please input a password.' 
PASSWORD = inputstr
 
;; ②入力確認(パスワードが入力されていない場合マクロ終了) 
strcompare PASSWORD '' 
if result=0 then 
    messagebox 'A password is not input.' 'Input error' 
    end 
endif
 
;; ③コマンド組立て 
COMMAND = HOSTADDR 
strconcat COMMAND ':22 /ssh /2 /auth=password /user=' 
strconcat COMMAND USERNAME 
strconcat COMMAND ' /passwd=' 
strconcat COMMAND PASSWORD
 
;; ④接続 
connect COMMAND
 
;; ⑤接続判定1(接続出来ない場合はメッセージを表示しマクロ終了) 
if result <> 2 then 
    messagebox 'It could not be connected.' 'Connection Error' 
    end 
endif
 
;; ⑥接続判定2(10秒以内にプロンプトが表示されない場合TeraTerm終了) 
timeout = 10 
wait '$' '#' 
if result=0 then 
    end 
endif
 
;; ⑦コマンド実行
; ファイルオープン
fileopen fhandle 'cmd.txt' 0

:loop
; 一行読み込み
filereadln fhandle line
if result goto fclose

yesnobox line 'Tera Term'  
if result=0 then
 end
endif

sendln line 
wait '$' '#'

; ファイル最後まで繰り返す
goto loop

:fclose
; ファイルクローズ
fileclose fhandle



;; ⑧マクロ終了 
end

2014年11月3日月曜日

winscpをバッチから使う

winscpにscriptという機能を使うとバッチ処理ができそう http://sourceforge.jp/projects/winscp/wiki/scripting

ganymed-ssh2を使ってコマンド実行

ganymed-ssh2を使ってコマンド実行 一回ごとに実行していか確認

引数 host port username password コマンドファイル
コマンドファイル1行を1コマンドとして実行

POM
 
  ch.ethz.ganymed
  ganymed-ssh2
  262
 
Java
package jp.tuyoyun.metatrader.sshclient;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;

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

public class App
{
 private static Scanner scan;

 public static void main(String[] args) throws Exception
 {
  Connection con = new Connection(args[0], Integer.parseInt(args[1]));
  con.connect();
  con.authenticateWithPassword(args[2], args[3]);
  File file = new File(args[4]);
  InputStream stream = new FileInputStream(file);
  BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF8"));
  String line = reader.readLine();
  while (line != null) {
   System.out.println("\ncommand----------------------------------------------------\n");
   System.out.println(line);
   System.out.println("-----------------------------------------------------------\n");
   boolean confirm = confirm();
   if (!confirm) {
    scan.close();
    reader.close();
    stream.close();
    con.close();
    return;
   }
   exec(con, line);
   line = reader.readLine();
  }
  scan.close();
  reader.close();
  stream.close();
  con.close();
 }

 private static boolean confirm() {
  System.out.println("execute command? y/n");
  scan = new Scanner(System.in);
  String confirm = scan.next();
  if ("y".equals(confirm)) {
   return true;
  }
  else if ("n".equals(confirm)) {
   return false;
  } else {
   return confirm();
  }
 }

 private static void exec(Connection con, String cmd) throws IOException, InterruptedException {
  Session session = con.openSession();
  session.execCommand(cmd);
  InputStream inputStream = session.getStdout();
  readResult(inputStream);
  inputStream = session.getStderr();
  readResult(inputStream);
  session.close();
 }

 private static void readResult(InputStream inputStream) throws UnsupportedEncodingException, IOException {
  BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF8"));
  String line = reader.readLine();
  while (line != null) {
   System.out.println(line);
   line = reader.readLine();
  }
  reader.close();
  inputStream.close();
 }
}