2012-03-01 11 views
0

私はモバイルデバイス上でUbuntuを稼働させることができました。私は、その上でいくつかのプロセスを自動化する必要があります。なぜなら、複雑な設定やはんだ付けワイヤがなければ、ユーザーの入力は全く不可能だからです。プロセスを自動化するBASH

私は実行する必要が

は、その後、パイプ、ここで標準入力に「はい、修正し、修正する」所望の出力である「印刷が別れ」:ここでは

~ # parted /dev/block/mmcblk0 print 
parted /dev/block/mmcblk0 print 
Warning: /dev/block/mmcblk0 contains GPT signatures, indicating that it has a 
GPT table. However, it does not have a valid fake msdos partition table, as it 
should. Perhaps it was corrupted -- possibly by a program that doesn't 
understand GPT partition tables. Or perhaps you deleted the GPT table, and are 
now using an msdos partition table. Is this a GPT partition table? 
Yes/No? yes 
yes 
yes 
Error: The backup GPT table is not at the end of the disk, as it should be. 
This might mean that another operating system believes the disk is smaller. 
Fix, by moving the backup to the end (and removing the old backup)? 
Fix/Ignore/Cancel? fix 
fix 
fix 
Warning: Not all of the space available to /dev/block/mmcblk0 appears to be 
used, you can fix the GPT to use all of the space (an extra 569312 blocks) or 
continue with the current setting? 
Fix/Ignore? fix 
fix 
fix 
Model: MMC SEM16G (sd/mmc) 
Disk /dev/block/mmcblk0: 15.9GB 
Sector size (logical/physical): 512B/512B 
Partition Table: gpt 

Number Start End  Size File system Name  Flags 
1  131kB 262kB 131kB    xloader 
2  262kB 524kB 262kB    bootloader 
3  524kB 16.3MB 15.7MB    recovery 
4  16.8MB 33.6MB 16.8MB    boot 
5  33.6MB 83.9MB 50.3MB    rom 
6  83.9MB 134MB 50.3MB    bootdata 
7  134MB 522MB 388MB    factory 
8  522MB 1164MB 642MB    system 
9  1164MB 1611MB 447MB    cache 
10  1611MB 2684MB 1074MB    media 
11  2684MB 15.6GB 12.9GB    userdata 

は、私が起草したものです。..

#! /bin/bash 
mkfifo Input 
mkfifo Output 
#Redirect commandline input from fifo to parted, Redirect output to fifo, background 
cat Input &| - parted print >Output & 
Line="" 
while [ 1 ] 
    do 
    while read Line 
    do 
     if [ $Line == *Yes\/No\?* ]; then 
     echo "yes">Input 
     fi 
     if [ $Line == *Fix\/Ignore/\Cancel\?* ]; then 
     echo "fix">Input 
     fi 
     if [ $Line == *Fix\/Ignore\?* ]; then 
     echo "fix">Input 
     fi 
     test $Line == *userdata* && break 
    done<Output 
    test $Line == *userdata* && break 
done 

しかし、これは動作しません。誰かが私がプログラムの出力をFIFOにリダイレクトするのを手伝ったら、そのデータを分析して、元のプログラムに戻すために別のFIFOに出力を向けるでしょうか?目的の結果が最初のコードブロックにあります。

+0

[期待]を使用しない理由(http://linux.die.net/man/1/expect) ? –

答えて

0

実行時に決して変更されない場合、必要な入力が何であるかを常に知っていれば、ファイルまたはHEREドキュメントからの入力をリダイレクトするだけで、何も複雑にする必要はありません。

必要な入力が実行ごとに変更される場合は、実行しようとしていることができないため、シェル以外のものを使用する必要があります。 perlは良い選択かもしれません。 (あなたはttyをシミュレートしようとしていないので、ここで期待する必要はありません)

+0

実際、私はTTYをエミュレートしていると思います。あたかもコマンドを入力しているかのように、プログラムへの入力を自律的に制御できるようにする必要があります。 – AdamOutler

+0

いいえ、そうではありません。 "TTYをエミュレートする"とは、stdinとstdoutが/ dev/ttyに接続されていないと機能しないため、ptyの下で対話型プログラムを実行することを意味します。例はtelnet、slogin、emacsのようなプログラムです。これとは対照的に、この場合、stdinとstdoutがパイプに接続されているか、何があるのか​​がほぼ確実にわかる通常のプログラムを扱っていました。 popen(3)はうまく動作します。 – Perry