特定の文字列のシリアルポートを監視するためにbashスクリプトを使用しようとしています。この文字列が表示されたら、一部のコマンドを接続機器に送り返す必要があります。これが私が接続しているルーターです。これが私が接続されているルーターで、ubootメニューが表示された後にコマンドを送信したいと思います。
ftdi-USB-UARTデバイスでminicomを直接使用すると(スクリプトを使用せずに)、すべてがうまく機能します。この文脈で「動作する」とは、次のことを意味します。
- 起動メニューの表示時間がカウントダウンされています。、数字を入力するか、カウントダウンが終了するまで、デバイスは入力を待っています。
- コマンドを送信するか、数字を入力できます。
- ルータは選択したオプションで「起動」されます。 (私の場合、システムはtftp-bootmodeで起動しますが、ここからサーバーIPなどを入力できます...)
今スクリプトを使用するとき。ルータは入力を気にせず、カウントダウンは実行されません。デフォルトオプションで直接起動します。 Raspberry Piでminicom + / dev / ttyAMA0を使用した場合と同じ動作です(ftdiデバイスは説明したように機能します)。
私のスクリプトにいくつかのパラメータがありません。おそらくsttyのための特別なオプションを選択する必要がありますか?
それとも、ルーターが「誰かが私にいくつかのコマンドを送信できる」ことを認識できるように、最初に特別な「制御文字」を送信する必要がありますか?
検索中の文字列を検出できますが、前述したように、ルーターは送信されたコマンドを認識しません。
#!/bin/bash
tty=/dev/ttyUSB0
exec 4<$tty 5>$tty
stty -F $tty 115200 -echo
while [ "${output}" != "Please choose the operation:" ]; do #wait for bootmenu to appear
read output <&4
echo "$output"
done
printf "\t\n ***** gotcha! ***** \n\n" #bootmenu is showing
echo -e "\x31" >&5 # echo '1' for taking boot option 1
printf "\t\n ***** echo '1' ***** \n\n"
while true; do #just for debugging (was command received?)...
read output <&4
echo "$output"
done
#commands for setting Target-IP, TFTP-Server-IP-address should follow here...
よろしくお願いします:-)
ベストアンサー1
echo -n "1" >&5
私にとってはそうでした。 ubootがラッピングしたくないようです。それ以外の場合は奇妙に動作します。
あなたの助けをいただきありがとうございます!
ここに「フル」スクリプトがあります。おそらく誰かに役立つでしょう。
#!/bin/bash
tty=/dev/ttyUSB0
exec 4<$tty 5>$tty
stty -F $tty 115200 -brkint -icrnl -imaxbel iutf8 -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
tftp_client_ip="10.10.30.111"
tftp_server_ip="10.10.30.1"
tftp_file="test.file"
while [ "$firstword" != "Please" ]; do # wait for bootmenu to apear
read -e output <&4
firstword=$(echo "$output" | cut -f1 -d" ")
echo "$output"
done
#printf "\t\n ***** ***** gotcha! ***** ***** \n\n"
sleep 0.5
# DONT SEND NEWLINEs - otherwise uboot doesn´t recognize commands !!!!!
echo -n "1" >&5 # echo '1' for taking boot option 1
printf "\t\n ***** ***** echo '1' ***** ***** \n\n"
# MUST TO WAIT FOR DELAY - try to fix that by "emulate" RETURN button?
sleep 5
#input TFTP-client IP
for((i=0;i<20;i++)); do
echo -ne "\b \b" >&5 #erase characters
sleep 0.05
done
printf "%s\r" "$tftp_client_ip" >&5
#input TFTP-server IP
for((i=0;i<20;i++)); do
echo -ne "\b \b" >&5 #erase characters
sleep 0.05
done
printf "%s\r" "$tftp_server_ip" >&5
#input TFTP-file
printf "%s\r" "$tftp_file" >&5
while true; do #just for debugging...
read -e output <&4
echo "$output"
done
# router should boot to RAM with "$tftp_file"